Permalink
Browse files

prototype for easier overpass integration

  • Loading branch information...
michael spreng
michael spreng committed Oct 20, 2017
1 parent e7a28fe commit ec280b45dd0b8a7a534b866d617bc706ce6a60a8
Showing with 62 additions and 19 deletions.
  1. +62 −19 src/js/leaflet.storage.layer.js
@@ -309,26 +309,54 @@ L.Storage.DataLayer = L.Class.extend({
fetchRemoteData: function () {
if (!this.isRemoteLayer()) return;
var from = parseInt(this.options.remoteData.from, 10),
to = parseInt(this.options.remoteData.to, 10);
if ((!isNaN(from) && this.map.getZoom() < from) ||
(!isNaN(to) && this.map.getZoom() > to) ) {
this.clear();
return;
if (this.options.remoteData && this.options.remoteData.url && this.options.remoteData.format)
{
/* the case of remote data */
var from = parseInt(this.options.remoteData.from, 10),
to = parseInt(this.options.remoteData.to, 10);
if ((!isNaN(from) && this.map.getZoom() < from) ||
(!isNaN(to) && this.map.getZoom() > to) ) {
this.clear();
return;
}
if (!this.options.remoteData.dynamic && this.hasDataLoaded()) return;
if (!this.isVisible()) return;
var self = this,
url = this.map.localizeUrl(this.options.remoteData.url);
if (this.options.remoteData.proxy) url = this.map.proxyUrl(url);
this.map.ajax({
uri: url,
verb: 'GET',
callback: function (raw) {
self.clear();
self.rawToGeoJSON(raw, self.options.remoteData.format, function (geojson) {self.fromGeoJSON(geojson);});
}
});
}
if (!this.options.remoteData.dynamic && this.hasDataLoaded()) return;
if (!this.isVisible()) return;
var self = this,
url = this.map.localizeUrl(this.options.remoteData.url);
if (this.options.remoteData.proxy) url = this.map.proxyUrl(url);
this.map.ajax({
uri: url,
verb: 'GET',
callback: function (raw) {
self.clear();
self.rawToGeoJSON(raw, self.options.remoteData.format, function (geojson) {self.fromGeoJSON(geojson);});
else
{
/* the case of overpass */
var from = parseInt(this.options.overpassData.from, 10),
to = parseInt(this.options.overpassData.to, 10);
if ((!isNaN(from) && this.map.getZoom() < from) ||
(!isNaN(to) && this.map.getZoom() > to) ) {
this.clear();
return;
}
});
if (!this.options.overpassData.dynamic && this.hasDataLoaded()) return;
if (!this.isVisible()) return;
var url = "https://overpass.osm.ch/api/interpreter?data=" + this.options.overpassData.query
var self = this,
url = this.map.localizeUrl(url);
this.map.ajax({
uri: url,
verb: 'GET',
callback: function (raw) {
self.clear();
self.rawToGeoJSON(raw, 'osm', function (geojson) {self.fromGeoJSON(geojson);});
}
});
}
},
onceLoaded: function (callback, context) {
@@ -389,7 +417,8 @@ L.Storage.DataLayer = L.Class.extend({
},
isRemoteLayer: function () {
return !!(this.options.remoteData && this.options.remoteData.url && this.options.remoteData.format);
return !!((this.options.remoteData && this.options.remoteData.url && this.options.remoteData.format)
|| (this.options.overpassData && this.options.overpassData.query));
},
isClustered: function () {
@@ -791,6 +820,20 @@ L.Storage.DataLayer = L.Class.extend({
builder = new L.S.FormBuilder(this, remoteDataFields);
remoteDataContainer.appendChild(builder.build());
if (!L.Util.isObject(this.options.overpasseData)) {
this.options.overpassData = {};
}
var overpassDataFields = [
['options.overpassData.query', {label: L._('Overpass query')}],
['options.overpassData.from', {label: L._('From zoom'), helpText: L._('Optionnal.')}],
['options.overpassData.to', {label: L._('To zoom'), helpText: L._('Optionnal.')}],
['options.overpassData.dynamic', {handler: 'Switch', label: L._('Dynamic'), helpEntries: 'dynamicRemoteData'}],
];
var overpassDataContainer = L.DomUtil.createFieldset(container, L._('Overpass'));
builder = new L.S.FormBuilder(this, overpassDataFields);
overpassDataContainer.appendChild(builder.build());
if (this.map.options.urls.datalayer_versions) this.buildVersionsFieldset(container);
var advancedActions = L.DomUtil.createFieldset(container, L._('Advanced actions'));

0 comments on commit ec280b4

Please sign in to comment.