Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add (Overpass based) POI layer #384

Merged
merged 10 commits into from
Mar 22, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,5 @@ Copyright (c) 2018 Norbert Renner and [contributors](https://github.com/nrenner/
Copyright (c) 2014-2021 Denis Pushkarev; [MIT License](https://github.com/zloirock/core-js/blob/master/LICENSE)
- [regenerator-runtime](https://github.com/facebook/regenerator/tree/master/packages/regenerator-runtime)
Copyright (c) 2014-present, Facebook, Inc.; [MIT License](https://github.com/facebook/regenerator/blob/master/packages/regenerator-runtime/LICENSE)
- [overpass-layer](https://github.com/plepe/overpass-layer)
Copyright (c) 2020 Stephan Bösch-Plepelits; [MIT License](https://github.com/plepe/overpass-layer/blob/master/LICENSE)
5 changes: 5 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
presets: [['@babel/preset-env', {}]],
sourceType: 'script',
exclude: [/node_modules\/(?!overpass-layer\/).*/],
};
5 changes: 0 additions & 5 deletions babel.config.json

This file was deleted.

19 changes: 19 additions & 0 deletions css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,25 @@ table.dataTable {
flex: auto;
}

/* reduce title font size in overpass popups */
.leaflet-popup-content h1 {
font-size: 1.2rem;
}

.overpass-tags th {
vertical-align: top;
}

.overpass-layer-icon i {
position: absolute;
top: 7px;
left: 7px;
color: white;
margin: auto;
display: inline-block;
font-size: 11px;
}

/* wrap toolbar controls */
.leaflet-top.leaflet-left {
bottom: 0;
Expand Down
8 changes: 8 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,14 @@ <h4 class="modal-title" data-i18n="layers.customize">Customize layers</h4>
>
Add overlay
</button>
<button
type="button"
id="custom_layers_add_overpass"
class="btn btn-success"
data-i18n="layers.add-overpass"
>
Add overpass query
</button>
<button
type="button"
id="custom_layers_remove"
Expand Down
20 changes: 20 additions & 0 deletions js/LayersConfig.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
BR.LayersConfig = L.Class.extend({
overpassFrontend: new OverpassFrontend(
(BR.conf.overpassBaseUrl || '//overpass-api.de/api/interpreter').replace('?data=', '')
),
defaultBaseLayers: BR.confLayers.defaultBaseLayers,
defaultOverlays: BR.confLayers.defaultOverlays,
legacyNameToIdMap: BR.confLayers.legacyNameToIdMap,
Expand Down Expand Up @@ -169,6 +172,21 @@ BR.LayersConfig = L.Class.extend({
return result;
},

createOverpassLayer: function (query) {
return new OverpassLayer({
overpassFrontend: this.overpassFrontend,
query: query,
minZoom: undefined,
stesie marked this conversation as resolved.
Show resolved Hide resolved
feature: {
title: '{{ tags.name }}',
body:
'<table class="overpass-tags">{% for k, v in tags %}{% if k[:5] != "addr:" %}<tr><th>{{ k }}</th><td>{% if k matches "/email/" %}<a href="mailto:{{ v }}">{{ v }}</a>{% elseif v matches "/^http/" %}<a href="{{ v }}">{{ v }}</a>{% elseif v matches "/^www/" %}<a href="http://{{ v }}">{{ v }}</a>{% else %}{{ v }}{% endif %}</td></tr>{% endif %}{% endfor %}</table>',
markerSymbol:
'<svg width="25px" height="41px" anchorX="12" anchorY="41" viewBox="0 0 32 52" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><path d="M16,1 C7.7146,1 1,7.65636364 1,15.8648485 C1,24.0760606 16,51 16,51 C16,51 31,24.0760606 31,15.8648485 C31,7.65636364 24.2815,1 16,1 L16,1 Z" fill="#436978"></path></svg><i class="fa fa-search icon-white" style="width: 25px;"></i>',
},
});
},

createLayer: function (layerData) {
var props = layerData.properties;
var url = props.url;
Expand Down Expand Up @@ -251,6 +269,8 @@ BR.LayersConfig = L.Class.extend({
if (props.subdomains) {
layer.subdomains = props.subdomains;
}
} else if (props.dataSource === 'OverpassAPI') {
layer = this.createOverpassLayer(props.query);
} else {
// JOSM
var josmUrl = url;
Expand Down
57 changes: 44 additions & 13 deletions js/control/Layers.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,30 @@ BR.Layers = L.Class.extend({
if (BR.Util.localStorageAvailable()) {
var layers = JSON.parse(localStorage.getItem('map/customLayers'));
for (a in layers) {
this._addLayer(a, layers[a].layer, layers[a].isOverlay);
this._addLayer(a, layers[a].layer, layers[a].isOverlay, layers[a].dataSource);
}
}
},

_loadTable: function () {
var layersData = [];
for (layer in this._customLayers) {
var isOverlay = this._customLayers[layer].isOverlay;
layersData.push([
layer,
this._customLayers[layer].layer._url,
isOverlay
? i18next.t('sidebar.layers.table.type_overlay')
: i18next.t('sidebar.layers.table.type_layer'),
]);
if (this._customLayers[layer].dataSource === 'OverpassAPI') {
layersData.push([
layer,
this._customLayers[layer].layer.options.query,
i18next.t('sidebar.layers.table.type_overpass_query'),
]);
} else {
var isOverlay = this._customLayers[layer].isOverlay;
layersData.push([
layer,
this._customLayers[layer].layer._url,
isOverlay
? i18next.t('sidebar.layers.table.type_overlay')
: i18next.t('sidebar.layers.table.type_layer'),
]);
}
}
if (this._layersTable != null) {
this._layersTable.destroy();
Expand Down Expand Up @@ -51,6 +59,7 @@ BR.Layers = L.Class.extend({

L.DomUtil.get('custom_layers_add_base').onclick = L.bind(this._addBaseLayer, this);
L.DomUtil.get('custom_layers_add_overlay').onclick = L.bind(this._addOverlay, this);
L.DomUtil.get('custom_layers_add_overpass').onclick = L.bind(this._addOverpassQuery, this);
L.DomUtil.get('custom_layers_remove').onclick = L.bind(this._remove, this);

this._loadLayers();
Expand Down Expand Up @@ -83,10 +92,10 @@ BR.Layers = L.Class.extend({
}
},

_addFromInput: function (isOverlay) {
_addFromInput: function (isOverlay, dataSource) {
var layer_name = L.DomUtil.get('layer_name').value;
var layer_url = L.DomUtil.get('layer_url').value;
if (layer_name.length > 0 && layer_url.length > 0) this._addLayer(layer_name, layer_url, isOverlay);
if (layer_name.length > 0 && layer_url.length > 0) this._addLayer(layer_name, layer_url, isOverlay, dataSource);
},

_addBaseLayer: function (evt) {
Expand All @@ -95,18 +104,28 @@ BR.Layers = L.Class.extend({
_addOverlay: function (evt) {
this._addFromInput(true);
},
_addOverpassQuery: function (evt) {
this._addFromInput(true, 'OverpassAPI');
},

_addLayer: function (layerName, layerUrl, isOverlay) {
_addLayer: function (layerName, layerUrl, isOverlay, dataSource) {
if (layerName in this._layers) return;

if (layerName in this._customLayers) return;

try {
var layer = L.tileLayer(layerUrl);
var layer;

if (dataSource === 'OverpassAPI') {
layer = this._layersControl.layersConfig.createOverpassLayer(layerUrl);
} else {
layer = L.tileLayer(layerUrl);
}

this._customLayers[layerName] = {
layer: layer,
isOverlay: isOverlay,
dataSource: dataSource,
};

if (isOverlay) {
Expand All @@ -128,6 +147,18 @@ BR.Layers = L.Class.extend({
localStorage.setItem(
'map/customLayers',
JSON.stringify(this._customLayers, function (k, v) {
if (v === undefined) {
return undefined;
}

if (v.dataSource === 'OverpassAPI') {
return {
dataSource: 'OverpassAPI',
isOverlay: true,
layer: v.layer.options.query,
};
}

// dont write Leaflet.Layer in localStorage; simply keep the URL
return v._url || v;
})
Expand Down
83 changes: 83 additions & 0 deletions layers/config/tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,88 @@ BR.confLayers.tree = {
]
}
]
},
'overpass': {
'amenity': {
'financial': [
'atm',
'bank',
],
'others': [
'bench',
'kneipp_water_cure',
'public_bath',
'shelter',
'shower',
'telephone',
'toilets',
'water_point',
],
'sustenance': [
'bar',
'bbq',
'biergarten',
'cafe',
'drinking_water',
'fast_food',
'food_court',
'ice_cream',
'pub',
'restaurant',
],
'transportation': [
'bicycle_parking',
'bicycle_rental',
'bicycle_repair_station',
'boat_rental',
'boat_sharing',
'bus_station',
'car_rental',
'car_sharing',
'car_wash',
'charging_station',
'ferry_terminal',
'fuel',
'grit_bin',
'motorcycle_parking',
'parking_entrance',
'parking',
'parking_space',
'taxi',
'vehicle_inspection',
]
},
'shop': {
'food': [
'bakery',
'beverages',
'butcher',
'cheese',
'coffee',
'convenience',
'greengrocer',
'health_food',
'ice_cream',
'organic',
]
},
'tourism': [
'apartment',
'artwork',
'attraction',
'camp_site',
'caravan_site',
'chalet',
'gallery',
'guest_house',
'hostel',
'hotel',
'information',
'motel',
'museum',
'picnic_site',
'viewpoint',
'wilderness_hut',
]
}
};
11 changes: 11 additions & 0 deletions layers/overpass/amenity/financial/atm.geojson
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"geometry": null,
"properties": {
"name": "ATM",
"id": "atm",
"overlay": true,
"dataSource": "OverpassAPI",
"query": "(node[amenity=atm]; node[amenity=bank][atm][atm!=no]; way[amenity=bank][atm][atm!=no];);"
},
"type": "Feature"
}
11 changes: 11 additions & 0 deletions layers/overpass/amenity/financial/bank.geojson
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"geometry": null,
"properties": {
"name": "Bank",
"id": "bank",
"overlay": true,
"dataSource": "OverpassAPI",
"query": "(node[amenity=bank]; way[amenity=bank];);"
},
"type": "Feature"
}
11 changes: 11 additions & 0 deletions layers/overpass/amenity/others/bench.geojson
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"geometry": null,
"properties": {
"name": "Bench",
"id": "bench",
"overlay": true,
"dataSource": "OverpassAPI",
"query": "node[amenity=bench];"
},
"type": "Feature"
}
11 changes: 11 additions & 0 deletions layers/overpass/amenity/others/kneipp_water_cure.geojson
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"geometry": null,
"properties": {
"name": "Kneipp water cure",
"id": "kneipp_water_cure",
"overlay": true,
"dataSource": "OverpassAPI",
"query": "(node[amenity=kneipp_water_cure]; way[amenity=kneipp_water_cure];);"
},
"type": "Feature"
}
11 changes: 11 additions & 0 deletions layers/overpass/amenity/others/public_bath.geojson
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"geometry": null,
"properties": {
"name": "Public bath",
"id": "public_bath",
"overlay": true,
"dataSource": "OverpassAPI",
"query": "(node[amenity=public_bath]; way[amenity=public_bath];);"
},
"type": "Feature"
}
11 changes: 11 additions & 0 deletions layers/overpass/amenity/others/shelter.geojson
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"geometry": null,
"properties": {
"name": "Shelter",
"id": "shelter",
"overlay": true,
"dataSource": "OverpassAPI",
"query": "(node[amenity=shelter]; way[amenity=shelter];);"
},
"type": "Feature"
}
11 changes: 11 additions & 0 deletions layers/overpass/amenity/others/shower.geojson
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"geometry": null,
"properties": {
"name": "Shower",
"id": "shower",
"overlay": true,
"dataSource": "OverpassAPI",
"query": "(node[amenity=shower]; way[amenity=shower];);"
},
"type": "Feature"
}
11 changes: 11 additions & 0 deletions layers/overpass/amenity/others/telephone.geojson
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"geometry": null,
"properties": {
"name": "Telephone",
"id": "telephone",
"overlay": true,
"dataSource": "OverpassAPI",
"query": "node[amenity=telephone];"
},
"type": "Feature"
}
Loading