Skip to content

Instantly share code, notes, and snippets.

@speters
Created August 19, 2019 15:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save speters/faa33c8ba1c8c707232c9c5f9e682607 to your computer and use it in GitHub Desktop.
Save speters/faa33c8ba1c8c707232c9c5f9e682607 to your computer and use it in GitHub Desktop.
NV-Pedia coverages
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
/*
NV-Pedia coverages to geoJSON
operate on e.g. https://www.nv-pedia.de/hafenplan-schlei2-modersitzki-werft/ via browser console
*/
old_log = console.log
//console.log = function() {};
var wkeys = Object.keys(window);
function sleep(millis)
{
var date = new Date();
var curDate = null;
do { curDate = new Date(); }
while(curDate-date < millis);
}
old_getJSON = $.getJSON;
jsoncb = function (data) {
$.each( data, function( key, val ) {
mapid = val.pid;
mapyear = val.year;
});
}
$.getJSON = function (url, data, success) {
$.ajax({
dataType: "json",
url: url,
data: data,
success: jsoncb,
async: false
})};
var featureGroup = L.featureGroup().addTo(map);
map.eachLayer(function(layer) {
if (layer instanceof L.Polygon) {
map.setView(layer.getBounds().getCenter(), 9);
var feature = layer.feature = layer.feature || {};
feature.type = "Feature";
feature.properties = feature.properties || {};
feature.properties["color"] = layer.options.color;
feature.properties["fillColor"] = layer.options.fillColor;
feature.properties["fillOpacity"] = layer.options.fillOpacity;
feature.properties["opacity"] = layer.options.opacity;
for (const key of wkeys) {
if (key.startsWith("a") && (typeof window[key].getBounds === "function")) {
if (window[key].getBounds().equals(layer.getBounds())) {
feature.properties["name"] = key;
if (typeof window["func"+key.substring(1)] === "function") {
var ufn = window["func"+key.substring(1)];
if (ufn.toString().search("updateMarkerStatus")) {
ufn();
feature.properties["info"] = $("#markerStatus").html();
}
}
break;
}
}
}
console.log("getMap() layer "+ feature.properties["name"] + " mapid "+ mapid + " mapyear "+mapyear);
getMap();
feature.properties["mapid"] = mapid;
feature.properties["mapyear"] = mapyear;
featureGroup.addLayer(layer);
}
});
console.log = old_log;
$.getJSON = old_getJSON;
JSON.stringify(featureGroup.toGeoJSON());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment