Add further support for special UI-elements; add documentation, fix a few bugs

This commit is contained in:
Pieter Vander Vennet 2020-10-17 02:37:53 +02:00
parent 3ab3cef249
commit 07e611bf10
12 changed files with 113 additions and 55 deletions

View file

@ -17,6 +17,7 @@ export class ElementStorage {
addElement(element): UIEventSource<any> {
const eventSource = new UIEventSource<any>(element.properties);
console.log("Creating a new tag storate for ", element.properties.id)
this._elements[element.properties.id] = eventSource;
return eventSource;
}

View file

@ -111,7 +111,10 @@ export class FilteredLayer {
if (this.filters.matches(tags)) {
const centerPoint = GeoOperations.centerpoint(feature);
feature.properties["_surface"] = "" + GeoOperations.surfaceAreaInSqMeters(feature);
const sqMeters = GeoOperations.surfaceAreaInSqMeters(feature);
feature.properties["_surface"] = "" + sqMeters;
feature.properties["_surface:ha"] = "" + Math.floor(sqMeters / 1000)/10;
const lat = centerPoint.geometry.coordinates[1];
const lon = centerPoint.geometry.coordinates[0]
feature.properties["_lon"] = "" + lat; // We expect a string here for lat/lon
@ -252,7 +255,7 @@ export class FilteredLayer {
const popup = L.popup({}, marker);
let uiElement: UIElement;
let content = undefined;
let p = marker.bindPopup(popup)
let p = marker.bindPopup(popup)
.on("popupopen", () => {
if (content === undefined) {
uiElement = self._showOnPopup(eventSource, feature);

View file

@ -28,7 +28,7 @@ export class ImageSearcher extends UIEventSource<{key: string, url: string}[]> {
private readonly _commons = new UIEventSource<string>("");
constructor(tags: UIEventSource<any>) {
constructor(tags: UIEventSource<any>, imagePrefix = "image", loadSpecial = true) {
super([]);
this._tags = tags;
@ -40,17 +40,17 @@ export class ImageSearcher extends UIEventSource<{key: string, url: string}[]> {
this._commons.addCallback(() => self.LoadCommons());
this._tags.addCallbackAndRun(() => self.LoadImages());
this._tags.addCallbackAndRun(() => self.LoadImages(imagePrefix, loadSpecial));
}
private AddImage(key: string, url: string) {
if (url === undefined || url === null || url === "") {
if (url === undefined || url === null || url === "") {
return;
}
for (const el of this.data) {
if (el.url === url) {
// This url is already seen -> don't add it
return;
}
}
@ -102,17 +102,18 @@ export class ImageSearcher extends UIEventSource<{key: string, url: string}[]> {
}
}
private LoadImages(imagePrefix: string = "image", loadAdditional = true): void {
const imageTag = this._tags.data.image;
private LoadImages(imagePrefix: string, loadAdditional: boolean): void {
console.log("Loading images from",this._tags)
const imageTag = this._tags.data[imagePrefix];
if (imageTag !== undefined) {
const bareImages = imageTag.split(";");
for (const bareImage of bareImages) {
this.AddImage("image", bareImage);
this.AddImage(imagePrefix, bareImage);
}
}
for (const key in this._tags.data) {
if (key.startsWith("image:")) {
if (key.startsWith(imagePrefix+":")) {
const url = this._tags.data[key]
this.AddImage(key, url);
}
@ -130,7 +131,7 @@ export class ImageSearcher extends UIEventSource<{key: string, url: string}[]> {
}
if (this._tags.data.mapillary) {
this.AddImage("mapillary", "https://www.mapillary.com/map/im/" + this._tags.data.mapillary)
this.AddImage(undefined,"https://www.mapillary.com/map/im/" + this._tags.data.mapillary)
}
}

View file

@ -29,6 +29,7 @@ export class Changes {
if(pending.length === 0){
return;
}
console.log("Sending ping",eventSource)
eventSource.ping();
this.uploadAll([], pending);
}