Skip to content

Commit

Permalink
fix(feature zoom): add click SourceFeatureType (#154)
Browse files Browse the repository at this point in the history
* independent SearchService & Locate by coord

* Ideas for API

* Highlight clickedfeature without zoom.

* Replace string for SourceFeatureType.Click + Zoom + PixelTolerance

* spacing
  • Loading branch information
pelord authored and mbarbeau committed May 18, 2018
1 parent 67346b8 commit a7f7dcb
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
6 changes: 5 additions & 1 deletion src/demo-app/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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))
}
}
}
3 changes: 2 additions & 1 deletion src/lib/feature/shared/feature.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ export enum FeatureFormat {

export enum SourceFeatureType {
Query = <any> 'Query',
Search = <any> 'Search'
Search = <any> 'Search',
Click = <any> 'Click'
}
10 changes: 8 additions & 2 deletions src/lib/overlay/shared/overlay.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions src/lib/query/shared/query.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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, {
Expand All @@ -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'
),
Expand Down

0 comments on commit a7f7dcb

Please sign in to comment.