_doc="Gives a list of features from the specified layer which this feature (partly) overlaps with. A point which is embedded in the feature is detected as well."+
"If the current feature is a point, all features that this point is embeded in are given.\n\n"+
"The returned value is `{ feat: GeoJSONFeature, overlap: number}[]` where `overlap` is the overlapping surface are (in m²) for areas, the overlapping length (in meter) if the current feature is a line or `undefined` if the current feature is a point.\n"+
"The resulting list is sorted in descending order by overlap. The feature with the most overlap will thus be the first in the list\n"+
"\n"+
"For example to get all objects which overlap or embed from a layer, use `_contained_climbing_routes_properties=feat.overlapWith('climbing_route')`"
_args=["...layerIds - one or more layer ids of the layer from which every feature is checked for overlap)"]
_doc="Calculates the distance between the feature and a specified point in meter. The input should either be a pair of coordinates, a geojson feature or the ID of an object";
_args=["feature OR featureID OR longitude","undefined OR latitude"]
_f(featuresPerLayer,feature){
return(arg0,lat)=>{
if(arg0===undefined){
returnundefined;
}
if(typeofarg0==="number"){
// Feature._lon and ._lat is conveniently place by one of the other metatags
_doc="Given either a list of geojson features or a single layer name, gives the single object which is nearest to the feature. In the case of ways/polygons, only the centerpoint is considered. Returns a single geojson feature or undefined if nothing is found (or not yet laoded)"
_args=["list of features or a layer name or '*' to get all features"]
_doc="Given either a list of geojson features or a single layer name, gives the n closest objects which are nearest to the feature (excluding the feature itself). In the case of ways/polygons, only the centerpoint is considered. "+
"Returns a list of `{feat: geojson, distance:number}` the empty list if nothing is found (or not yet loaded)\n\n"+
"If a 'unique tag key' is given, the tag with this key will only appear once (e.g. if 'name' is given, all features will have a different name)"
// We want to see the tag `uniquetag=some_value` only once in the entire list (e.g. to prevent road segements of identical names to fill up the list of 'names of nearby roads')
// AT this point, we have found a closer segment with the same, identical tag
_doc="Gets the property of the feature, parses it (as JSON) and returns it. Might return 'undefined' if not defined, null, ..."
_args=["key"]
_f(params,feat){
returnkey=>{
constvalue=feat.properties[key]
if(value===undefined){
returnundefined;
}
try{
constparsed=JSON.parse(value)
if(parsed===null){
returnundefined;
}
returnparsed;
}catch(e){
console.warn("Could not parse property "+key+" due to: "+e+", the value is "+value)
returnundefined;
}
}
}
}
exportclassExtraFunctions{
staticreadonlyintro=newCombine([
newTitle("Calculating tags with Javascript",2),
"In some cases, it is useful to have some tags calculated based on other properties. Some useful tags are available by default (e.g. `lat`, `lon`, `_country`), as detailed above.",
"It is also possible to calculate your own tags - but this requires some javascript knowledge.",
"",
"Before proceeding, some warnings:",
newList([
"DO NOT DO THIS AS BEGINNER",
"**Only do this if all other techniques fail** This should _not_ be done to create a rendering effect, only to calculate a specific value",
"**THIS MIGHT BE DISABLED WITHOUT ANY NOTICE ON UNOFFICIAL THEMES** As unofficial themes might be loaded from the internet, this is the equivalent of injecting arbitrary code into the client. It'll be disabled if abuse occurs."
]),
"To enable this feature, add a field `calculatedTags` in the layer object, e.g.:",