Formatting

This commit is contained in:
Pieter Vander Vennet 2021-06-24 02:34:13 +02:00
parent 2883ae7122
commit 41ee3a7e58

View file

@ -16,12 +16,12 @@ export default class ShowDataLayer {
private readonly _leafletMap: UIEventSource<L.Map>; private readonly _leafletMap: UIEventSource<L.Map>;
private _cleanCount = 0; private _cleanCount = 0;
private readonly _enablePopups: boolean; private readonly _enablePopups: boolean;
private readonly _features : UIEventSource<{ feature: any, freshness: Date }[]> private readonly _features: UIEventSource<{ feature: any, freshness: Date }[]>
constructor(features: UIEventSource<{ feature: any, freshness: Date }[]>, constructor(features: UIEventSource<{ feature: any, freshness: Date }[]>,
leafletMap: UIEventSource<L.Map>, leafletMap: UIEventSource<L.Map>,
layoutToUse: UIEventSource<LayoutConfig>, layoutToUse: UIEventSource<LayoutConfig>,
enablePopups= true, enablePopups = true,
zoomToFeatures = false) { zoomToFeatures = false) {
this._leafletMap = leafletMap; this._leafletMap = leafletMap;
this._enablePopups = enablePopups; this._enablePopups = enablePopups;
@ -46,7 +46,7 @@ export default class ShowDataLayer {
} }
const mp = leafletMap.data; const mp = leafletMap.data;
if(mp === undefined){ if (mp === undefined) {
return; return;
} }
@ -75,7 +75,7 @@ export default class ShowDataLayer {
mp.addLayer(geoLayer) mp.addLayer(geoLayer)
} }
if(zoomToFeatures){ if (zoomToFeatures) {
mp.fitBounds(geoLayer.getBounds()) mp.fitBounds(geoLayer.getBounds())
} }
@ -89,7 +89,6 @@ export default class ShowDataLayer {
} }
private createStyleFor(feature) { private createStyleFor(feature) {
const tagsSource = State.state.allElements.addOrGetElement(feature); const tagsSource = State.state.allElements.addOrGetElement(feature);
// Every object is tied to exactly one layer // Every object is tied to exactly one layer
@ -111,7 +110,7 @@ export default class ShowDataLayer {
const style = layer.GenerateLeafletStyle(tagSource, !(layer.title === undefined && (layer.tagRenderings ?? []).length === 0)); const style = layer.GenerateLeafletStyle(tagSource, !(layer.title === undefined && (layer.tagRenderings ?? []).length === 0));
const baseElement = style.icon.html; const baseElement = style.icon.html;
if(!this._enablePopups){ if (!this._enablePopups) {
baseElement.SetStyle("cursor: initial !important") baseElement.SetStyle("cursor: initial !important")
} }
return L.marker(latLng, { return L.marker(latLng, {
@ -180,7 +179,7 @@ export default class ShowDataLayer {
if (selected.properties.id === feature.properties.id) { if (selected.properties.id === feature.properties.id) {
// A small sanity check to prevent infinite loops: // A small sanity check to prevent infinite loops:
// If a feature is rendered both as way and as point, opening one popup might trigger the other to open, which might trigger the one to open again // If a feature is rendered both as way and as point, opening one popup might trigger the other to open, which might trigger the one to open again
if(selected.geometry.type === feature.geometry.type){ if (selected.geometry.type === feature.geometry.type) {
leafletLayer.openPopup() leafletLayer.openPopup()
} }
@ -190,15 +189,15 @@ export default class ShowDataLayer {
} }
private CreateGeojsonLayer(): L.Layer { private CreateGeojsonLayer(): L.Layer {
const self = this; const self = this;
const data = { const data = {
type: "FeatureCollection", type: "FeatureCollection",
features: [] features: []
} }
// @ts-ignore // @ts-ignore
return L.geoJSON(data, { return L.geoJSON(data, {
style: feature => self.createStyleFor(feature), style: feature => self.createStyleFor(feature),
pointToLayer: (feature, latLng) => self.pointToLayer(feature, latLng), pointToLayer: (feature, latLng) => self.pointToLayer(feature, latLng),
onEachFeature: (feature, leafletLayer) => self.postProcessFeature(feature, leafletLayer) onEachFeature: (feature, leafletLayer) => self.postProcessFeature(feature, leafletLayer)
}); });