Merge branch 'develop'

This commit is contained in:
Pieter Vander Vennet 2022-02-11 04:33:22 +01:00
commit bdc3d65e8a
15 changed files with 188 additions and 115 deletions

View file

@ -18,6 +18,7 @@ export default class FilterConfig {
originalTagsSpec: string | AndOrTagConfigJson
fields: { name: string, type: string }[]
}[];
public readonly defaultSelection : number
constructor(json: FilterConfigJson, context: string) {
if (json.options === undefined) {
@ -35,6 +36,7 @@ export default class FilterConfig {
throw `A filter was given where the options aren't a list at ${context}`
}
this.id = json.id;
let defaultSelection : number = undefined
this.options = json.options.map((option, i) => {
const ctx = `${context}.options[${i}]`;
const question = Translations.T(
@ -66,9 +68,18 @@ export default class FilterConfig {
}
})
if(option.default){
if(defaultSelection === undefined){
defaultSelection = i;
}else{
throw `Invalid filter: multiple filters are set as default, namely ${i} and ${defaultSelection} at ${context}`
}
}
return {question: question, osmTags: osmTags, fields, originalTagsSpec: option.osmTags};
});
this.defaultSelection = defaultSelection ?? 0
if (this.options.some(o => o.fields.length > 0) && this.options.length > 1) {
throw `Invalid filter at ${context}: a filter with textfields should only offer a single option.`
@ -77,6 +88,8 @@ export default class FilterConfig {
if (this.options.length > 1 && this.options[0].osmTags !== undefined) {
throw "Error in " + context + "." + this.id + ": the first option of a multi-filter should always be the 'reset' option and not have any filters"
}
}
public initState(): UIEventSource<FilterState> {
@ -88,7 +101,14 @@ export default class FilterConfig {
return "" + state.state
}
const defaultValue = this.options.length > 1 ? "0" : ""
let defaultValue = ""
if(this.options.length > 1){
defaultValue = ""+this.defaultSelection
}else{
if(this.defaultSelection > 0){
defaultValue = ""+this.defaultSelection
}
}
const qp = QueryParameters.GetQueryParameter("filter-" + this.id, defaultValue, "State of filter " + this.id)
if (this.options.length > 1) {

View file

@ -14,6 +14,7 @@ export default interface FilterConfigJson {
options: {
question: string | any;
osmTags?: AndOrTagConfigJson | string,
default?: boolean,
fields?: {
name: string,
type?: string | "string"

View file

@ -33,44 +33,65 @@ export interface LayerConfigJson {
/**
* This determines where the data for the layer is fetched.
* There are some options:
* This determines where the data for the layer is fetched: from OSM or from an external geojson dataset.
*
* # Query OSM directly
* source: {osmTags: "key=value"}
* will fetch all objects with given tags from OSM.
* Currently, this will create a query to overpass and fetch the data - in the future this might fetch from the OSM API
* If no 'geojson' is defined, data will be fetched from overpass and the OSM-API.
*
* # Query OSM Via the overpass API with a custom script
* source: {overpassScript: "<custom overpass tags>"} when you want to do special things. _This should be really rare_.
* This means that the data will be pulled from overpass with this script, and will ignore the osmTags for the query
* However, for the rest of the pipeline, the OsmTags will _still_ be used. This is important to enable layers etc...
* Every source _must_ define which tags _must_ be present in order to be picked up.
*
*
* # A single geojson-file
* source: {geoJson: "https://my.source.net/some-geo-data.geojson"}
* fetches a geojson from a third party source
*
* # A tiled geojson source
* source: {geoJson: "https://my.source.net/some-tile-geojson-{layer}-{z}-{x}-{y}.geojson", geoJsonZoomLevel: 14}
* to use a tiled geojson source. The web server must offer multiple geojsons. {z}, {x} and {y} are substituted by the location; {layer} is substituted with the id of the loaded layer
*
* Some API's use a BBOX instead of a tile, this can be used by specifying {y_min}, {y_max}, {x_min} and {x_max}
* Some API's use a mercator-projection (EPSG:900913) instead of WGS84. Set the flag `mercatorCrs: true` in the source for this
*
* Note that both geojson-options might set a flag 'isOsmCache' indicating that the data originally comes from OSM too
*
*
* NOTE: the previous format was 'overpassTags: AndOrTagConfigJson | string', which is interpreted as a shorthand for source: {osmTags: "key=value"}
* While still supported, this is considered deprecated
*/
source: ({ osmTags: AndOrTagConfigJson | string, overpassScript?: string } |
{ osmTags: AndOrTagConfigJson | string, geoJson: string, geoJsonZoomLevel?: number, isOsmCache?: boolean, mercatorCrs?: boolean }) & ({
/**
* The maximum amount of seconds that a tile is allowed to linger in the cache
*/
maxCacheAge?: number
})
source:
({
/**
* Every source must set which tags have to be present in order to load the given layer.
*/
osmTags: AndOrTagConfigJson | string
/**
* The maximum amount of seconds that a tile is allowed to linger in the cache
*/
maxCacheAge?: number
}) &
({ /* # Query OSM Via the overpass API with a custom script
* source: {overpassScript: "<custom overpass tags>"} when you want to do special things. _This should be really rare_.
* This means that the data will be pulled from overpass with this script, and will ignore the osmTags for the query
* However, for the rest of the pipeline, the OsmTags will _still_ be used. This is important to enable layers etc...
*/
overpassScript?: string
} |
{
/**
* The actual source of the data to load, if loaded via geojson.
*
* # A single geojson-file
* source: {geoJson: "https://my.source.net/some-geo-data.geojson"}
* fetches a geojson from a third party source
*
* # A tiled geojson source
* source: {geoJson: "https://my.source.net/some-tile-geojson-{layer}-{z}-{x}-{y}.geojson", geoJsonZoomLevel: 14}
* to use a tiled geojson source. The web server must offer multiple geojsons. {z}, {x} and {y} are substituted by the location; {layer} is substituted with the id of the loaded layer
*
* Some API's use a BBOX instead of a tile, this can be used by specifying {y_min}, {y_max}, {x_min} and {x_max}
*/
geoJson: string,
/**
* To load a tiled geojson layer, set the zoomlevel of the tiles
*/
geoJsonZoomLevel?: number,
/**
* Indicates that the upstream geojson data is OSM-derived.
* Useful for e.g. merging or for scripts generating this cache
*/
isOsmCache?: boolean,
/**
* Some API's use a mercator-projection (EPSG:900913) instead of WGS84. Set the flag `mercatorCrs: true` in the source for this
*/
mercatorCrs?: boolean,
/**
* Some API's have an id-field, but give it a different name.
* Setting this key will rename this field into 'id'
*/
idKey?: string
})
/**
*
@ -113,7 +134,7 @@ export interface LayerConfigJson {
/**
* Advanced option - might be set by the theme compiler
*
*
* If true, this data will _always_ be loaded, even if the theme is disabled
*/
forceLoad?: false | boolean
@ -148,7 +169,7 @@ export interface LayerConfigJson {
* If not specified, the OsmLink and wikipedia links will be used by default.
* Use an empty array to hide them.
* Note that "defaults" will insert all the default titleIcons (which are added automatically)
*
*
* Type: icon[]
*/
titleIcons?: (string | TagRenderingConfigJson)[] | ["defaults"];
@ -194,7 +215,7 @@ export interface LayerConfigJson {
/**
* Example images, which show real-life pictures of what such a feature might look like
*
*
* Type: image
*/
exampleImages?: string[]
@ -251,7 +272,7 @@ export interface LayerConfigJson {
/**
* All the extra questions for filtering
*/
filter?: (FilterConfigJson) [] | {sameAs: string},
filter?: (FilterConfigJson) [] | { sameAs: string },
/**
* This block defines under what circumstances the delete dialog is shown for objects of this layer.

View file

@ -15,7 +15,6 @@ import LineRenderingConfig from "./LineRenderingConfig";
import PointRenderingConfigJson from "./Json/PointRenderingConfigJson";
import LineRenderingConfigJson from "./Json/LineRenderingConfigJson";
import {TagRenderingConfigJson} from "./Json/TagRenderingConfigJson";
import {UIEventSource} from "../../Logic/UIEventSource";
import BaseUIElement from "../../UI/BaseUIElement";
import Combine from "../../UI/Base/Combine";
import Title from "../../UI/Base/Title";
@ -108,11 +107,13 @@ export default class LayerConfig extends WithContextLoader {
this.source = new SourceConfig(
{
osmTags: osmTags,
geojsonSource: json.source["geoJson"],
geojsonSourceLevel: json.source["geoJsonZoomLevel"],
geojsonSource: json.source["geoJson"],
geojsonSourceLevel: json.source["geoJsonZoomLevel"],
overpassScript: json.source["overpassScript"],
isOsmCache: json.source["isOsmCache"],
mercatorCrs: json.source["mercatorCrs"]
mercatorCrs: json.source["mercatorCrs"],
idKey: json.source["idKey"]
},
json.id
);
@ -236,7 +237,7 @@ export default class LayerConfig extends WithContextLoader {
console.log(json.mapRendering)
throw("The layer " + this.id + " does not have any maprenderings defined and will thus not show up on the map at all. If this is intentional, set maprenderings to 'null' instead of '[]'")
} else if (!hasCenterRendering && this.lineRendering.length === 0 && !this.source.geojsonSource?.startsWith("https://api.openstreetmap.org/api/0.6/notes.json")) {
throw "The layer " + this.id + " might not render ways. This might result in dropped information"
throw "The layer " + this.id + " might not render ways. This might result in dropped information (at "+context+")"
}
}

View file

@ -9,6 +9,7 @@ export default class SourceConfig {
public geojsonZoomLevel?: number;
public isOsmCacheLayer: boolean;
public readonly mercatorCrs: boolean;
public readonly idKey : string
constructor(params: {
mercatorCrs?: boolean;
@ -17,6 +18,7 @@ export default class SourceConfig {
geojsonSource?: string,
isOsmCache?: boolean,
geojsonSourceLevel?: number,
idKey?: string
}, context?: string) {
let defined = 0;
@ -47,5 +49,6 @@ export default class SourceConfig {
this.geojsonZoomLevel = params.geojsonSourceLevel;
this.isOsmCacheLayer = params.isOsmCache ?? false;
this.mercatorCrs = params.mercatorCrs ?? false;
this.idKey= params.idKey
}
}