Skip to content

Commit

Permalink
feat(map): Prevent zooming on result if already contained in map exte…
Browse files Browse the repository at this point in the history
…nt (#193)

* feat(*) Prevent zooming on result if already contained im map extent

* refactor(*) refactor zoomif to zoomIfOutMapExtent & interface to enum

* fix(overlay) zoom if outside map extent

* refactor(demo) set to false because it is not provided in search module.
  • Loading branch information
pelord authored and mbarbeau committed Oct 3, 2018
1 parent 34449dc commit d917886
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 15 deletions.
3 changes: 2 additions & 1 deletion demo/src/app/geo/feature/feature.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
IgoMap,
DataSourceService,
LayerService,
OverlayAction,
OverlayService,
Feature,
FeatureType,
Expand Down Expand Up @@ -105,6 +106,6 @@ export class AppFeatureComponent {
}

handleFeatureSelect(feature: Feature) {
this.overlayService.setFeatures([feature], 'zoom');
this.overlayService.setFeatures([feature], OverlayAction.ZoomIfOutMapExtent);
}
}
3 changes: 2 additions & 1 deletion demo/src/app/geo/search/search.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
SearchService,
Feature,
FeatureType,
OverlayAction,
OverlayService
} from '@igo2/geo';

Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion demo/src/environments/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion projects/geo/src/lib/overlay/shared/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from './overlay.directive';
export * from './overlay.service';
export * from './overlay.interface';
export * from './overlay.enum';
14 changes: 9 additions & 5 deletions projects/geo/src/lib/overlay/shared/overlay.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]'
Expand Down Expand Up @@ -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);
}
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions projects/geo/src/lib/overlay/shared/overlay.enum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export enum OverlayAction {
None,
Move,
Zoom,
ZoomIfOutMapExtent
}
1 change: 0 additions & 1 deletion projects/geo/src/lib/overlay/shared/overlay.interface.ts

This file was deleted.

6 changes: 3 additions & 3 deletions projects/geo/src/lib/overlay/shared/overlay.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
MapService,
LayerService,
OverlayService,
OverlayAction,
Feature,
FeatureType,
AnyDataSourceOptions,
Expand All @@ -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();

Expand Down

0 comments on commit d917886

Please sign in to comment.