Add better way handling

This commit is contained in:
Pieter Vander Vennet 2020-07-22 00:50:30 +02:00
parent 0bb5abec3c
commit 1373bd106e
10 changed files with 46 additions and 13 deletions

View file

@ -6,6 +6,7 @@ import { Changes } from "./Changes";
import L from "leaflet"
import { GeoOperations } from "./GeoOperations";
import { UIElement } from "../UI/UIElement";
import {LayerDefinition} from "../Customizations/LayerDefinition";
/***
* A filtered layer is a layer which offers a 'set-data' function
@ -18,7 +19,7 @@ import { UIElement } from "../UI/UIElement";
*/
export class FilteredLayer {
public readonly name: string;
public readonly name: string | UIElement;
public readonly filters: TagsFilter;
public readonly isDisplayed: UIEventSource<boolean> = new UIEventSource(true);
@ -32,6 +33,7 @@ export class FilteredLayer {
/** The featurecollection from overpass
*/
private _dataFromOverpass;
private _wayHandling: number;
/** List of new elements, geojson features
*/
private _newElements = [];
@ -43,15 +45,17 @@ export class FilteredLayer {
private _showOnPopup: (tags: UIEventSource<any>) => UIElement;
constructor(
name: string,
name: string | UIElement,
map: Basemap, storage: ElementStorage,
changes: Changes,
filters: TagsFilter,
maxAllowedOverlap: number,
wayHandling: number,
style: ((properties) => any),
selectedElement: UIEventSource<any>,
showOnPopup: ((tags: UIEventSource<any>) => UIElement)
) {
this._wayHandling = wayHandling;
this._selectedElement = selectedElement;
this._showOnPopup = showOnPopup;
@ -66,6 +70,7 @@ export class FilteredLayer {
this._style = style;
this._storage = storage;
this._maxAllowedOverlap = maxAllowedOverlap;
const self = this;
this.isDisplayed.addCallback(function (isDisplayed) {
if (self._geolayer !== undefined && self._geolayer !== null) {
@ -86,10 +91,17 @@ export class FilteredLayer {
public SetApplicableData(geojson: any): any {
const leftoverFeatures = [];
const selfFeatures = [];
for (const feature of geojson.features) {
for (let feature of geojson.features) {
// feature.properties contains all the properties
var tags = TagUtils.proprtiesToKV(feature.properties);
if (this.filters.matches(tags)) {
if(feature.geometry.type !== "Point"){
if(this._wayHandling === LayerDefinition.WAYHANDLING_CENTER_AND_WAY){
selfFeatures.push(GeoOperations.centerpoint(feature));
}else if(this._wayHandling === LayerDefinition.WAYHANDLING_CENTER_ONLY){
feature = GeoOperations.centerpoint(feature);
}
}
selfFeatures.push(feature);
} else {
leftoverFeatures.push(feature);

View file

@ -6,6 +6,15 @@ export class GeoOperations {
return turf.area(feature);
}
static centerpoint(feature: any)
{
const newFeature= turf.center(feature);
newFeature.properties = feature.properties;
newFeature.id = feature.id;
return newFeature;
}
static featureIsContainedInAny(feature: any,
shouldNotContain: any[],
maxOverlapPercentage: number): boolean {