From c359d43b1518cff3904c1c57d4b9035b5e958bd3 Mon Sep 17 00:00:00 2001 From: pietervdvn Date: Wed, 6 Jan 2021 02:09:04 +0100 Subject: [PATCH] Add standalone bicycle library theme, search now opens the popup of the found object --- Customizations/AllKnownLayouts.ts | 2 + InitUiElements.ts | 2 + Logic/Osm/Geocoding.ts | 3 +- Logic/Tags.ts | 8 +- Logic/Web/Hash.ts | 10 +- Logic/Web/QueryParameters.ts | 2 +- Models/Constants.ts | 2 +- State.ts | 2 +- UI/BigComponents/SearchAndGo.ts | 6 +- UI/OpeningHours/OpeningHoursInput.ts | 17 +- UI/ShowDataLayer.ts | 10 +- .../bicycle_library/bicycle_library.svg | 45 ++--- assets/tagRenderings/questions.json | 1 + .../bicycle_library/bicycle_library.json | 27 +++ assets/themes/bicycle_library/logo.svg | 166 ++++++++++++++++++ 15 files changed, 260 insertions(+), 43 deletions(-) create mode 100644 assets/themes/bicycle_library/bicycle_library.json create mode 100644 assets/themes/bicycle_library/logo.svg diff --git a/Customizations/AllKnownLayouts.ts b/Customizations/AllKnownLayouts.ts index 3195daa18c..2a3467e3b1 100644 --- a/Customizations/AllKnownLayouts.ts +++ b/Customizations/AllKnownLayouts.ts @@ -20,6 +20,7 @@ import * as surveillance_cameras from "../assets/themes/surveillance_cameras/sur import * as trees from "../assets/themes/trees/trees.json" import * as personal from "../assets/themes/personalLayout/personalLayout.json" import * as playgrounds from "../assets/themes/playgrounds/playgrounds.json" +import * as bicycle_lib from "../assets/themes/bicycle_library/bicycle_library.json" import LayerConfig from "./JSON/LayerConfig"; import LayoutConfig from "./JSON/LayoutConfig"; import SharedLayers from "./SharedLayers"; @@ -57,6 +58,7 @@ export class AllKnownLayouts { new LayoutConfig(drinking_water), new LayoutConfig(nature), new LayoutConfig(cyclestreets), + new LayoutConfig(bicycle_lib), new LayoutConfig(maps), new LayoutConfig(fritures), new LayoutConfig(benches), diff --git a/InitUiElements.ts b/InitUiElements.ts index c12ca087ae..de9fe3f880 100644 --- a/InitUiElements.ts +++ b/InitUiElements.ts @@ -40,6 +40,7 @@ import FeatureSwitched from "./UI/Base/FeatureSwitched"; import FeatureDuplicatorPerLayer from "./Logic/FeatureSource/FeatureDuplicatorPerLayer"; import LayerConfig from "./Customizations/JSON/LayerConfig"; import ShowDataLayer from "./UI/ShowDataLayer"; +import Hash from "./Logic/Web/Hash"; export class InitUiElements { @@ -132,6 +133,7 @@ export class InitUiElements { if (feature === undefined) { State.state.fullScreenMessage.setData(undefined); + Hash.hash.setData(undefined); } if (feature?.properties === undefined) { return; diff --git a/Logic/Osm/Geocoding.ts b/Logic/Osm/Geocoding.ts index 85f5c5ea29..f2ee260f2e 100644 --- a/Logic/Osm/Geocoding.ts +++ b/Logic/Osm/Geocoding.ts @@ -5,7 +5,8 @@ export class Geocoding { private static readonly host = "https://nominatim.openstreetmap.org/search?"; static Search(query: string, - handleResult: ((places: { display_name: string, lat: number, lon: number, boundingbox: number[] }[]) => void), + handleResult: ((places: { display_name: string, lat: number, lon: number, boundingbox: number[], + osm_type: string, osm_id: string}[]) => void), onFail: (() => void)) { const b = State.state.leafletMap.data.getBounds(); console.log(b); diff --git a/Logic/Tags.ts b/Logic/Tags.ts index f409cc1212..1b849511c5 100644 --- a/Logic/Tags.ts +++ b/Logic/Tags.ts @@ -454,19 +454,19 @@ export class TagUtils { static MatchesMultiAnswer(tag: TagsFilter, tags: any): boolean { const splitted = TagUtils.SplitKeys([tag]); - console.log("Matching multianswer", tag, tags) for (const splitKey in splitted) { const neededValues = splitted[splitKey]; + if(tags[splitKey] === undefined) { + return false; + } + const actualValue = tags[splitKey].split(";"); for (const neededValue of neededValues) { - console.log("needed", neededValue, "have: ", actualValue, actualValue.indexOf(neededValue) ) if (actualValue.indexOf(neededValue) < 0) { - console.log("NOT FOUND") return false; } } } - console.log("OK") return true; } } \ No newline at end of file diff --git a/Logic/Web/Hash.ts b/Logic/Web/Hash.ts index 6ca2d99e5f..f9329b2e2d 100644 --- a/Logic/Web/Hash.ts +++ b/Logic/Web/Hash.ts @@ -2,11 +2,17 @@ import {UIEventSource} from "../UIEventSource"; export default class Hash { - public static Get() : UIEventSource{ + public static hash : UIEventSource = Hash.Get(); + + private static Get() : UIEventSource{ const hash = new UIEventSource(window.location.hash.substr(1)); hash.addCallback(h => { + if(h === undefined || h === ""){ + window.location.hash = ""; + return; + } h = h.replace(/\//g, "_"); - return window.location.hash = "#" + h; + window.location.hash = "#" + h; }); window.onhashchange = () => { hash.setData(window.location.hash.substr(1)) diff --git a/Logic/Web/QueryParameters.ts b/Logic/Web/QueryParameters.ts index 08cd37a764..715ee32a80 100644 --- a/Logic/Web/QueryParameters.ts +++ b/Logic/Web/QueryParameters.ts @@ -62,7 +62,7 @@ export class QueryParameters { parts.push(encodeURIComponent(key) + "=" + encodeURIComponent(QueryParameters.knownSources[key].data)) } - history.replaceState(null, "", "?" + parts.join("&") + "#" + Hash.Get().data); + history.replaceState(null, "", "?" + parts.join("&") + "#" + Hash.hash.data); } diff --git a/Models/Constants.ts b/Models/Constants.ts index 5df0c1f7cf..35214dbb82 100644 --- a/Models/Constants.ts +++ b/Models/Constants.ts @@ -1,7 +1,7 @@ import { Utils } from "../Utils"; export default class Constants { - public static vNumber = "0.3.0c"; + public static vNumber = "0.3.1 "; // The user journey states thresholds when a new feature gets unlocked public static userJourney = { diff --git a/State.ts b/State.ts index 7b92cf896a..0f3e43d124 100644 --- a/State.ts +++ b/State.ts @@ -201,7 +201,7 @@ export default class State { ); - const h = Hash.Get(); + const h = Hash.hash; this.selectedElement.addCallback(selected => { if (selected === undefined) { h.setData(""); diff --git a/UI/BigComponents/SearchAndGo.ts b/UI/BigComponents/SearchAndGo.ts index 6603ef89ec..9d945a65a2 100644 --- a/UI/BigComponents/SearchAndGo.ts +++ b/UI/BigComponents/SearchAndGo.ts @@ -8,6 +8,7 @@ import State from "../../State"; import {TextField} from "../Input/TextField"; import {Geocoding} from "../../Logic/Osm/Geocoding"; import Translations from "../i18n/Translations"; +import Hash from "../../Logic/Web/Hash"; export default class SearchAndGo extends UIElement { @@ -61,11 +62,14 @@ export default class SearchAndGo extends UIElement { return; } - const bb = result[0].boundingbox; + const poi = result[0]; + const bb = poi.boundingbox; const bounds: [[number, number], [number, number]] = [ [bb[0], bb[2]], [bb[1], bb[3]] ] + State.state.selectedElement. setData(undefined); + Hash.hash.setData(poi.osm_type+"_"+poi.osm_id); State.state.leafletMap.data.fitBounds(bounds); self._placeholder.setData(Translations.t.general.search.search); }, diff --git a/UI/OpeningHours/OpeningHoursInput.ts b/UI/OpeningHours/OpeningHoursInput.ts index 7a9ca26ca0..8e9a7c9b83 100644 --- a/UI/OpeningHours/OpeningHoursInput.ts +++ b/UI/OpeningHours/OpeningHoursInput.ts @@ -13,6 +13,7 @@ import {OH} from "./OpeningHours"; import {InputElement} from "../Input/InputElement"; import PublicHolidayInput from "./PublicHolidayInput"; import Translations from "../i18n/Translations"; +import {Utils} from "../../Utils"; export default class OpeningHoursInput extends InputElement { @@ -63,15 +64,13 @@ export default class OpeningHoursInput extends InputElement { this._phSelector = new PublicHolidayInput(ph); function update() { - let rules = OH.ToString(rulesFromOhPicker.data); - if (leftoverRules.data.length != 0) { - rules += ";" + leftoverRules.data.join(";") - } - const phData = ph.data; - if (phData !== undefined && phData !== "") { - rules += ";" + phData; - } - value.setData(rules); + const regular = OH.ToString(rulesFromOhPicker.data); + const rules : string[] = [ + regular, + ...leftoverRules.data, + ph.data + ] + value.setData(Utils.NoEmpty(rules).join(";")); } rulesFromOhPicker.addCallback(update); diff --git a/UI/ShowDataLayer.ts b/UI/ShowDataLayer.ts index 17ac8ae811..9968d76f5f 100644 --- a/UI/ShowDataLayer.ts +++ b/UI/ShowDataLayer.ts @@ -68,6 +68,12 @@ export default class ShowDataLayer { action(); } }); + Hash.hash.addCallback(id => { + const action = self._onSelectedTrigger[id]; + if(action){ + action(); + } + }) } @@ -139,9 +145,9 @@ export default class ShowDataLayer { leafletLayer.openPopup(); uiElement.Activate(); } - + this._onSelectedTrigger[feature.properties.id.replace("/","_")] = this._onSelectedTrigger[id]; - if (feature.properties.id.replace(/\//g, "_") === Hash.Get().data) { + if (feature.properties.id.replace(/\//g, "_") === Hash.hash.data) { // This element is in the URL, so this is a share link // We already open it uiElement.Activate(); diff --git a/assets/layers/bicycle_library/bicycle_library.svg b/assets/layers/bicycle_library/bicycle_library.svg index 3692a1b5dd..a4d017c46e 100644 --- a/assets/layers/bicycle_library/bicycle_library.svg +++ b/assets/layers/bicycle_library/bicycle_library.svg @@ -22,7 +22,7 @@ image/svg+xml - + @@ -81,34 +81,37 @@ inkscape:window-height="999" id="namedview6" showgrid="false" - inkscape:zoom="0.74071072" - inkscape:cx="204.95027" - inkscape:cy="554.1468" + inkscape:zoom="0.37035536" + inkscape:cx="-364.34347" + inkscape:cy="764.959" inkscape:window-x="0" inkscape:window-y="0" inkscape:window-maximized="1" - inkscape:current-layer="layer2" /> + inkscape:current-layer="layer1" + showguides="true" + inkscape:guide-bbox="true"> + + - - - - + + diff --git a/assets/tagRenderings/questions.json b/assets/tagRenderings/questions.json index 16265f668d..e9aeefa71d 100644 --- a/assets/tagRenderings/questions.json +++ b/assets/tagRenderings/questions.json @@ -8,6 +8,7 @@ "phone": { "question": { "en": "What is the phone number of {name}?", + "nl": "Wat is het telefoonnummer van {name}?", "de": "Was ist die Telefonnummer von {name}?" }, "render": "{phone}", diff --git a/assets/themes/bicycle_library/bicycle_library.json b/assets/themes/bicycle_library/bicycle_library.json new file mode 100644 index 0000000000..45f22c81a9 --- /dev/null +++ b/assets/themes/bicycle_library/bicycle_library.json @@ -0,0 +1,27 @@ +{ + "id": "bicyclelib", + "maintainer": "MapComplete", + "version": "2020-08-29", + "language": [ + "en", + "nl", + ], + "title": { + "en": "Bicycle libraries", + "nl": "Fietsbibliotheken", + }, + "description": { + "nl": "Een fietsbibliotheek is een plaats waar men een fiets kan lenen, vaak voor een klein bedrag per jaar. Een typisch voorbeeld zijn kinderfietsbibliotheken, waar men een fiets op maat van het kind kan lenen. Is het kind de fiets ontgroeid, dan kan het te kleine fietsje omgeruild worden voor een grotere.", + "en": "A bicycle library is a place where bicycles can be lent, often for a small yearly fee. A notable use case are bicycle libraries for kids, which allows them to change for a bigger bike when they've outgrown their current bike" + }, + "icon": "./assets/themes/bicycle_library/logo.svg", + "socialImage": null, + "startLat": 0, + "startLon": 0, + "startZoom": 1, + "widenFactor": 0.05, + "roamingRenderings": [], + "layers": [ + "bicycle_library" + ] +} \ No newline at end of file diff --git a/assets/themes/bicycle_library/logo.svg b/assets/themes/bicycle_library/logo.svg new file mode 100644 index 0000000000..7256b88586 --- /dev/null +++ b/assets/themes/bicycle_library/logo.svg @@ -0,0 +1,166 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +