Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(*) Prevent zooming on result if already contained in map extent #193

Merged
merged 10 commits into from
Oct 3, 2018
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