diff --git a/demo/src/app/geo/feature/feature.component.ts b/demo/src/app/geo/feature/feature.component.ts index 45910b10e9..374e7f3a5d 100644 --- a/demo/src/app/geo/feature/feature.component.ts +++ b/demo/src/app/geo/feature/feature.component.ts @@ -5,6 +5,7 @@ import { IgoMap, DataSourceService, LayerService, + OverlayAction, OverlayService, Feature, FeatureType, @@ -105,6 +106,6 @@ export class AppFeatureComponent { } handleFeatureSelect(feature: Feature) { - this.overlayService.setFeatures([feature], 'zoom'); + this.overlayService.setFeatures([feature], OverlayAction.ZoomIfOutMapExtent); } } diff --git a/demo/src/app/geo/search/search.component.ts b/demo/src/app/geo/search/search.component.ts index 58f609aa2d..6568cbb6f4 100644 --- a/demo/src/app/geo/search/search.component.ts +++ b/demo/src/app/geo/search/search.component.ts @@ -9,6 +9,7 @@ import { SearchService, Feature, FeatureType, + OverlayAction, OverlayService } from '@igo2/geo'; @@ -70,7 +71,7 @@ export class AppSearchComponent { handleFeatureSelect(feature: Feature) { if (feature.type === FeatureType.Feature) { - this.overlayService.setFeatures([feature], 'zoom'); + this.overlayService.setFeatures([feature], OverlayAction.ZoomIfOutMapExtent); } else if (feature.type === FeatureType.DataSource) { this.layerService.createAsyncLayer(feature.layer).subscribe(layer => { this.map.addLayer(layer); diff --git a/demo/src/environments/environment.ts b/demo/src/environments/environment.ts index c0a95815da..816b9b2561 100644 --- a/demo/src/environments/environment.ts +++ b/demo/src/environments/environment.ts @@ -37,7 +37,7 @@ export const environment: Environment = { locateUrl: 'https://ws.mapserver.transports.gouv.qc.ca/swtq', limit: 5, locateLimit: 15, - enabled: true + enabled: false }, icherche: { searchUrl: 'https://geoegl.msp.gouv.qc.ca/icherche/geocode', diff --git a/projects/geo/src/lib/overlay/shared/index.ts b/projects/geo/src/lib/overlay/shared/index.ts index a518239180..1c388bc43e 100644 --- a/projects/geo/src/lib/overlay/shared/index.ts +++ b/projects/geo/src/lib/overlay/shared/index.ts @@ -1,3 +1,3 @@ export * from './overlay.directive'; export * from './overlay.service'; -export * from './overlay.interface'; +export * from './overlay.enum'; diff --git a/projects/geo/src/lib/overlay/shared/overlay.directive.ts b/projects/geo/src/lib/overlay/shared/overlay.directive.ts index 9bf2213ddc..93700900d1 100644 --- a/projects/geo/src/lib/overlay/shared/overlay.directive.ts +++ b/projects/geo/src/lib/overlay/shared/overlay.directive.ts @@ -11,7 +11,7 @@ import { SourceFeatureType } from '../../feature/shared/feature.enum'; import { Feature } from '../../feature/shared/feature.interface'; import { OverlayService } from '../shared/overlay.service'; -import { OverlayAction } from '../shared/overlay.interface'; +import { OverlayAction } from '../shared/overlay.enum'; @Directive({ selector: '[igoOverlay]' @@ -68,16 +68,20 @@ export class OverlayDirective implements OnInit, OnDestroy { }, this); if (features[0].sourceType === SourceFeatureType.Click) { if (olextent.intersects(featureExtent, this.map.getExtent())) { - action = 'none'; + action = OverlayAction.None; } else { - action = 'move'; + action = OverlayAction.Move; } } if (!olextent.isEmpty(featureExtent)) { - if (action === 'zoom') { + if (action === OverlayAction.Zoom) { this.map.zoomToExtent(extent); - } else if (action === 'move') { + } else if (action === OverlayAction.Move) { this.map.moveToExtent(extent); + } else if (action === OverlayAction.ZoomIfOutMapExtent) { + if (!olextent.intersects(featureExtent, this.map.getExtent())) { + this.map.zoomToExtent(extent); + } } } } diff --git a/projects/geo/src/lib/overlay/shared/overlay.enum.ts b/projects/geo/src/lib/overlay/shared/overlay.enum.ts new file mode 100644 index 0000000000..893c5e1e1a --- /dev/null +++ b/projects/geo/src/lib/overlay/shared/overlay.enum.ts @@ -0,0 +1,6 @@ +export enum OverlayAction { + None, + Move, + Zoom, + ZoomIfOutMapExtent + } diff --git a/projects/geo/src/lib/overlay/shared/overlay.interface.ts b/projects/geo/src/lib/overlay/shared/overlay.interface.ts deleted file mode 100644 index ef74062675..0000000000 --- a/projects/geo/src/lib/overlay/shared/overlay.interface.ts +++ /dev/null @@ -1 +0,0 @@ -export type OverlayAction = 'none' | 'move' | 'zoom'; diff --git a/projects/geo/src/lib/overlay/shared/overlay.service.ts b/projects/geo/src/lib/overlay/shared/overlay.service.ts index 4f95c15e89..2ce10a7ab4 100644 --- a/projects/geo/src/lib/overlay/shared/overlay.service.ts +++ b/projects/geo/src/lib/overlay/shared/overlay.service.ts @@ -3,7 +3,7 @@ import { BehaviorSubject } from 'rxjs'; import { Feature } from '../../feature/shared/feature.interface'; -import { OverlayAction } from './overlay.interface'; +import { OverlayAction } from './overlay.enum'; @Injectable({ providedIn: 'root' @@ -16,11 +16,11 @@ export class OverlayService { constructor() {} - setFeatures(features: Feature[], action: OverlayAction = 'none') { + setFeatures(features: Feature[], action: OverlayAction = OverlayAction.None) { this.features$.next([features, action]); } clear() { - this.features$.next([[], 'none']); + this.features$.next([[], OverlayAction.None]); } } diff --git a/projects/tools/src/lib/search-results-tool/search-results-tool.component.ts b/projects/tools/src/lib/search-results-tool/search-results-tool.component.ts index 114d703be3..e31aa6bfa3 100644 --- a/projects/tools/src/lib/search-results-tool/search-results-tool.component.ts +++ b/projects/tools/src/lib/search-results-tool/search-results-tool.component.ts @@ -6,6 +6,7 @@ import { MapService, LayerService, OverlayService, + OverlayAction, Feature, FeatureType, AnyDataSourceOptions, @@ -31,13 +32,13 @@ export class SearchResultsToolComponent { handleFeatureFocus(feature: Feature) { if (feature.type === FeatureType.Feature) { - this.overlayService.setFeatures([feature], 'move'); + this.overlayService.setFeatures([feature], OverlayAction.Move); } } handleFeatureSelect(feature: Feature) { if (feature.type === FeatureType.Feature) { - this.overlayService.setFeatures([feature], 'zoom'); + this.overlayService.setFeatures([feature], OverlayAction.ZoomIfOutMapExtent); } else if (feature.type === FeatureType.DataSource) { const map = this.mapService.getMap();