From a7f7dcb98d0f70826f12cd0586087f1ab8247415 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-=C3=89tienne=20Lord?= <7397743+pelord@users.noreply.github.com> Date: Fri, 18 May 2018 09:37:53 -0400 Subject: [PATCH] fix(feature zoom): add click SourceFeatureType (#154) * independent SearchService & Locate by coord * Ideas for API * Highlight clickedfeature without zoom. * Replace string for SourceFeatureType.Click + Zoom + PixelTolerance * spacing --- src/demo-app/app/app.component.ts | 6 +++++- src/lib/feature/shared/feature.enum.ts | 3 ++- src/lib/overlay/shared/overlay.directive.ts | 10 ++++++++-- src/lib/query/shared/query.directive.ts | 5 +++-- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/demo-app/app/app.component.ts b/src/demo-app/app/app.component.ts index efff305f45..0208bdf7ff 100644 --- a/src/demo-app/app/app.component.ts +++ b/src/demo-app/app/app.component.ts @@ -4,7 +4,7 @@ import { FormGroup, FormBuilder, FormControl, Validators } from '@angular/forms' import { ContextService, Feature, FeatureType, FeatureService, IgoMap, LanguageService, LayerService, MapService, MessageService, - OverlayService, ToolService } from '../../lib'; + OverlayService, ToolService, SourceFeatureType } from '../../lib'; import { AnyDataSourceContext, DataSourceService } from '../../lib/datasource'; @@ -98,6 +98,10 @@ export class AppComponent implements OnInit { const features: Feature[] = results.features; if (features[0]) { this.featureService.updateFeatures(features, features[0].source); + const firstClickFeature = features.filter(feature => + feature.sourceType === SourceFeatureType.Click)[0] + this.featureService.features$.subscribe(f => + this.featureService.selectFeature(firstClickFeature)) } } } diff --git a/src/lib/feature/shared/feature.enum.ts b/src/lib/feature/shared/feature.enum.ts index ebeb24345c..af9b4e1a2d 100644 --- a/src/lib/feature/shared/feature.enum.ts +++ b/src/lib/feature/shared/feature.enum.ts @@ -11,5 +11,6 @@ export enum FeatureFormat { export enum SourceFeatureType { Query = 'Query', - Search = 'Search' + Search = 'Search', + Click = 'Click' } diff --git a/src/lib/overlay/shared/overlay.directive.ts b/src/lib/overlay/shared/overlay.directive.ts index 46da8e2581..ee6fa7218a 100644 --- a/src/lib/overlay/shared/overlay.directive.ts +++ b/src/lib/overlay/shared/overlay.directive.ts @@ -4,7 +4,7 @@ import { Subscription } from 'rxjs/Subscription'; import * as ol from 'openlayers'; import { MapBrowserComponent, IgoMap } from '../../map'; -import { Feature } from '../../feature'; +import { Feature, SourceFeatureType } from '../../feature'; import { OverlayService } from '../shared/overlay.service'; import { OverlayAction } from '../shared/overlay.interface'; @@ -61,7 +61,13 @@ export class OverlayDirective implements OnInit, OnDestroy { this.map.addOverlay(olFeature); }, this); - + if (features[0].sourceType === SourceFeatureType.Click) { + if (ol.extent.intersects(featureExtent, this.map.getExtent())) { + action = 'none'; + } else { + action = 'move'; + } + } if (!ol.extent.isEmpty(featureExtent)) { if (action === 'zoom') { this.map.zoomToExtent(extent); diff --git a/src/lib/query/shared/query.directive.ts b/src/lib/query/shared/query.directive.ts index 02b83bbcb8..33e8e22223 100644 --- a/src/lib/query/shared/query.directive.ts +++ b/src/lib/query/shared/query.directive.ts @@ -18,7 +18,7 @@ import { LanguageService } from '../../core'; import { IgoMap } from '../../map/shared'; import { MapBrowserComponent } from '../../map/map-browser'; import { Layer } from '../../layer'; -import { Feature } from '../../feature'; +import { Feature, SourceFeatureType } from '../../feature'; import { QueryService } from '../shared/query.service'; @@ -101,7 +101,7 @@ export class QueryDirective implements AfterViewInit, OnDestroy { feature.set('clickedTitle', title); clickedFeatures.push(feature); } - } + }, { hitTolerance: 5 } ); const featuresGeoJSON = JSON.parse( format.writeFeatures(clickedFeatures, { @@ -113,6 +113,7 @@ export class QueryDirective implements AfterViewInit, OnDestroy { let parsedClickedFeatures: Feature[] = []; parsedClickedFeatures = featuresGeoJSON.features.map(f => Object.assign({}, f, { + sourceType: SourceFeatureType.Click, source: this.languageService.translate.instant( 'igo.clickOnMap.clickedFeature' ),