Add feature to the featureInfoBox so that geometry is available there as well

This commit is contained in:
Pieter Vander Vennet 2020-07-22 01:07:32 +02:00
parent 1373bd106e
commit 8268c0d054
7 changed files with 39 additions and 18 deletions

View file

@ -90,7 +90,7 @@ export class LayerDefinition {
title?: TagRenderingOptions, title?: TagRenderingOptions,
elementsToShow?: TagDependantUIElementConstructor[], elementsToShow?: TagDependantUIElementConstructor[],
maxAllowedOverlapPercentage?: number, maxAllowedOverlapPercentage?: number,
waysToCenterPoints?: boolean, wayHandling?: number,
style?: (tags: any) => { style?: (tags: any) => {
color: string, color: string,
icon: any icon: any
@ -108,11 +108,12 @@ export class LayerDefinition {
this.title = options.title; this.title = options.title;
this.elementsToShow = options.elementsToShow; this.elementsToShow = options.elementsToShow;
this.style = options.style; this.style = options.style;
this.wayHandling = options.waysToCenterPoints ?? LayerDefinition.WAYHANDLING_DEFAULT; this.wayHandling = options.wayHandling ?? LayerDefinition.WAYHANDLING_DEFAULT;
} }
asLayer(basemap: Basemap, allElements: ElementStorage, changes: Changes, userDetails: UIEventSource<UserDetails>, selectedElement: UIEventSource<any>, asLayer(basemap: Basemap, allElements: ElementStorage, changes: Changes, userDetails: UIEventSource<UserDetails>,
showOnPopup: (tags: UIEventSource<(any)>) => UIElement): selectedElement: UIEventSource<{feature: any}>,
showOnPopup: (tags: UIEventSource<(any)>, feature: any) => UIElement):
FilteredLayer { FilteredLayer {
return new FilteredLayer( return new FilteredLayer(
this.name, this.name,

View file

@ -25,6 +25,13 @@ export class NatureReserves extends LayerDefinition {
this.style = this.generateStyleFunction(); this.style = this.generateStyleFunction();
this.elementsToShow = [ this.elementsToShow = [
new ImageCarouselWithUploadConstructor(), new ImageCarouselWithUploadConstructor(),
new TagRenderingOptions({
freeform: {
key: "_surface",
renderTemplate: "{_surface}m²",
template: "$$$"
}
}),
new NameQuestion(), new NameQuestion(),
new AccessTag(), new AccessTag(),
new OperatorTag(), new OperatorTag(),

View file

@ -41,8 +41,8 @@ export class FilteredLayer {
* The leaflet layer object which should be removed on rerendering * The leaflet layer object which should be removed on rerendering
*/ */
private _geolayer; private _geolayer;
private _selectedElement: UIEventSource<any>; private _selectedElement: UIEventSource<{feature: any}>;
private _showOnPopup: (tags: UIEventSource<any>) => UIElement; private _showOnPopup: (tags: UIEventSource<any>, feature: any) => UIElement;
constructor( constructor(
name: string | UIElement, name: string | UIElement,
@ -52,8 +52,8 @@ export class FilteredLayer {
maxAllowedOverlap: number, maxAllowedOverlap: number,
wayHandling: number, wayHandling: number,
style: ((properties) => any), style: ((properties) => any),
selectedElement: UIEventSource<any>, selectedElement: UIEventSource<{feature: any}>,
showOnPopup: ((tags: UIEventSource<any>) => UIElement) showOnPopup: ((tags: UIEventSource<any>, feature: any) => UIElement)
) { ) {
this._wayHandling = wayHandling; this._wayHandling = wayHandling;
this._selectedElement = selectedElement; this._selectedElement = selectedElement;
@ -95,6 +95,7 @@ export class FilteredLayer {
// feature.properties contains all the properties // feature.properties contains all the properties
var tags = TagUtils.proprtiesToKV(feature.properties); var tags = TagUtils.proprtiesToKV(feature.properties);
if (this.filters.matches(tags)) { if (this.filters.matches(tags)) {
feature.properties["_surface"] = GeoOperations.surfaceAreaInSqMeters(feature);
if(feature.geometry.type !== "Point"){ if(feature.geometry.type !== "Point"){
if(this._wayHandling === LayerDefinition.WAYHANDLING_CENTER_AND_WAY){ if(this._wayHandling === LayerDefinition.WAYHANDLING_CENTER_AND_WAY){
selfFeatures.push(GeoOperations.centerpoint(feature)); selfFeatures.push(GeoOperations.centerpoint(feature));
@ -213,8 +214,8 @@ export class FilteredLayer {
layer.on("click", function (e) { layer.on("click", function (e) {
console.log("Selected ", feature) console.log("Selected ", feature)
self._selectedElement.setData(feature.properties); self._selectedElement.setData({feature: feature});
const uiElement = self._showOnPopup(eventSource); const uiElement = self._showOnPopup(eventSource, feature);
const popup = L.popup() const popup = L.popup()
.setContent(uiElement.Render()) .setContent(uiElement.Render())
.setLatLng(e.latlng) .setLatLng(e.latlng)

View file

@ -15,7 +15,7 @@ export class StrayClickHandler {
constructor( constructor(
basemap: Basemap, basemap: Basemap,
selectElement: UIEventSource<any>, selectElement: UIEventSource<{ feature: any }>,
fullScreenMessage: UIEventSource<UIElement>, fullScreenMessage: UIEventSource<UIElement>,
uiToShow: (() => UIElement)) { uiToShow: (() => UIElement)) {
this._basemap = basemap; this._basemap = basemap;

View file

@ -15,6 +15,13 @@ import Translations from "./i18n/Translations";
export class FeatureInfoBox extends UIElement { export class FeatureInfoBox extends UIElement {
/**
* The actual GEOJSON-object, with geometry and stuff
*/
private _feature: any;
/**
* The tags, wrapped in a global event source
*/
private _tagsES: UIEventSource<any>; private _tagsES: UIEventSource<any>;
private _changes: Changes; private _changes: Changes;
private _userDetails: UIEventSource<UserDetails>; private _userDetails: UIEventSource<UserDetails>;
@ -31,8 +38,8 @@ export class FeatureInfoBox extends UIElement {
private _oneSkipped = Translations.t.general.oneSkippedQuestion.Clone(); private _oneSkipped = Translations.t.general.oneSkippedQuestion.Clone();
private _someSkipped = Translations.t.general.skippedQuestions.Clone(); private _someSkipped = Translations.t.general.skippedQuestions.Clone();
constructor( constructor(
feature: any,
tagsES: UIEventSource<any>, tagsES: UIEventSource<any>,
title: TagRenderingOptions | UIElement, title: TagRenderingOptions | UIElement,
elementsToShow: TagDependantUIElementConstructor[], elementsToShow: TagDependantUIElementConstructor[],
@ -40,6 +47,7 @@ export class FeatureInfoBox extends UIElement {
userDetails: UIEventSource<UserDetails> userDetails: UIEventSource<UserDetails>
) { ) {
super(tagsES); super(tagsES);
this._feature = feature;
this._tagsES = tagsES; this._tagsES = tagsES;
this._changes = changes; this._changes = changes;
this._userDetails = userDetails; this._userDetails = userDetails;

View file

@ -15,14 +15,14 @@ export class SimpleAddUI extends UIElement {
private _addButtons: UIElement[]; private _addButtons: UIElement[];
private _lastClickLocation: UIEventSource<{ lat: number; lon: number }>; private _lastClickLocation: UIEventSource<{ lat: number; lon: number }>;
private _changes: Changes; private _changes: Changes;
private _selectedElement: UIEventSource<any>; private _selectedElement: UIEventSource<{feature: any}>;
private _dataIsLoading: UIEventSource<boolean>; private _dataIsLoading: UIEventSource<boolean>;
private _userDetails: UIEventSource<UserDetails>; private _userDetails: UIEventSource<UserDetails>;
constructor(zoomlevel: UIEventSource<{ zoom: number }>, constructor(zoomlevel: UIEventSource<{ zoom: number }>,
lastClickLocation: UIEventSource<{ lat: number, lon: number }>, lastClickLocation: UIEventSource<{ lat: number, lon: number }>,
changes: Changes, changes: Changes,
selectedElement: UIEventSource<any>, selectedElement: UIEventSource<{feature: any}>,
dataIsLoading: UIEventSource<boolean>, dataIsLoading: UIEventSource<boolean>,
userDetails: UIEventSource<UserDetails>, userDetails: UIEventSource<UserDetails>,
addButtons: { name: UIElement; icon: string; tags: Tag[]; layerToAddTo: FilteredLayer }[], addButtons: { name: UIElement; icon: string; tags: Tag[]; layerToAddTo: FilteredLayer }[],
@ -55,7 +55,7 @@ export class SimpleAddUI extends UIElement {
const loc = self._lastClickLocation.data; const loc = self._lastClickLocation.data;
let feature = self._changes.createElement(option.tags, loc.lat, loc.lon); let feature = self._changes.createElement(option.tags, loc.lat, loc.lon);
option.layerToAddTo.AddNewElement(feature); option.layerToAddTo.AddNewElement(feature);
self._selectedElement.setData(feature.properties); self._selectedElement.setData({feature: feature});
} }
} }

View file

@ -118,7 +118,8 @@ const secondsTillChangesAreSaved = new UIEventSource<number>(0);
// This message is shown full screen on mobile devices // This message is shown full screen on mobile devices
const fullScreenMessage = new UIEventSource<UIElement>(undefined); const fullScreenMessage = new UIEventSource<UIElement>(undefined);
const selectedElement = new UIEventSource<any>(undefined); // The latest element that was selected - used to generate the right UI at the right place
const selectedElement = new UIEventSource<{feature: any}>(undefined);
const locationControl = new UIEventSource<{ lat: number, lon: number, zoom: number }>({ const locationControl = new UIEventSource<{ lat: number, lon: number, zoom: number }>({
@ -179,9 +180,10 @@ let minZoom = 0;
for (const layer of layoutToUse.layers) { for (const layer of layoutToUse.layers) {
const generateInfo = (tagsES) => { const generateInfo = (tagsES, feature) => {
return new FeatureInfoBox( return new FeatureInfoBox(
feature,
tagsES, tagsES,
layer.title, layer.title,
layer.elementsToShow, layer.elementsToShow,
@ -229,7 +231,8 @@ new StrayClickHandler(bm, selectedElement, fullScreenMessage, () => {
/** /**
* Show the questions and information for the selected element on the fullScreen * Show the questions and information for the selected element on the fullScreen
*/ */
selectedElement.addCallback((data) => { selectedElement.addCallback((feature) => {
const data = feature.feature.properties;
// Which is the applicable set? // Which is the applicable set?
for (const layer of layoutToUse.layers) { for (const layer of layoutToUse.layers) {
@ -238,6 +241,7 @@ selectedElement.addCallback((data) => {
// This layer is the layer that gives the questions // This layer is the layer that gives the questions
const featureBox = new FeatureInfoBox( const featureBox = new FeatureInfoBox(
feature.feature,
allElements.getElement(data.id), allElements.getElement(data.id),
layer.title, layer.title,
layer.elementsToShow, layer.elementsToShow,