From fe62bf724c477979a16b6e8b3d0965ab3e380390 Mon Sep 17 00:00:00 2001 From: yopaseopor Date: Sat, 12 Dec 2020 00:32:29 +0100 Subject: [PATCH 1/2] Update index.js --- src/index.js | 131 +++++++++++++++++++++++++++------------------------ 1 file changed, 70 insertions(+), 61 deletions(-) diff --git a/src/index.js b/src/index.js index a0f237b..7204f08 100644 --- a/src/index.js +++ b/src/index.js @@ -29,68 +29,77 @@ $(function () { var layerGroup = overlay['group'], vectorProperties = overlay, vector; + + + if (overlay['geojson'] !== undefined) { + var vectorSource = new ol.source.Vector({ + format: new ol.format.GeoJSON(), + url: overlay['geojson'] + }) + } else { + var vectorSource = new ol.source.Vector({ + format: new ol.format.OSMXML2(), + loader: function (extent, resolution, projection) { + loading.show(); + var me = this; + var epsg4326Extent = ol.proj.transformExtent(extent, projection, 'EPSG:4326'); + var query = '[maxsize:536870912];' + overlay['query']; // Memory limit 512 MiB + //var query = layerQuery; + query = query.replace(/{{bbox}}/g, epsg4326Extent[1] + ',' + epsg4326Extent[0] + ',' + epsg4326Extent[3] + ',' + epsg4326Extent[2]); + + var client = new XMLHttpRequest(); + client.open('POST', config.overpassApi()); + client.onloadend = function () { + loading.hide(); + }; + client.onerror = function () { + console.error('[' + client.status + '] Error loading data.'); + me.removeLoadedExtent(extent); + vector.setVisible(false); + }; + client.onload = function () { + if (client.status === 200) { + var xmlDoc = $.parseXML(client.responseText), + xml = $(xmlDoc), + remark = xml.find('remark'), + nodosLength = xml.find('node').length; + + if (remark.length !== 0) { + console.error('Error:', remark.text()); + $('
').html(remark.text()).dialog({ + modal: true, + title: 'Error', + close: function () { + $(this).dialog('destroy'); + } + }); + client.onerror.call(this); + } else { + console.log('Nodes Found:', nodosLength); + if (nodosLength === 0) { + $('
').html(config.i18n.noNodesFound).dialog({ + modal: true, + //title: 'Error', + close: function () { + $(this).dialog('destroy'); + } + }); + } + var features = new ol.format.OSMXML2().readFeatures(xmlDoc, { + featureProjection: map.getView().getProjection() + }); + me.addFeatures(features); + } + } else { + client.onerror.call(this); + } + }; + client.send(query); + }, + strategy: ol.loadingstrategy.bbox + }); + } - var vectorSource = new ol.source.Vector({ - format: new ol.format.OSMXML2(), - loader: function (extent, resolution, projection) { - loading.show(); - var me = this; - var epsg4326Extent = ol.proj.transformExtent(extent, projection, 'EPSG:4326'); - var query = '[maxsize:536870912];' + overlay['query']; // Memory limit 512 MiB - //var query = layerQuery; - query = query.replace(/{{bbox}}/g, epsg4326Extent[1] + ',' + epsg4326Extent[0] + ',' + epsg4326Extent[3] + ',' + epsg4326Extent[2]); - - var client = new XMLHttpRequest(); - client.open('POST', config.overpassApi()); - client.onloadend = function () { - loading.hide(); - }; - client.onerror = function () { - console.error('[' + client.status + '] Error loading data.'); - me.removeLoadedExtent(extent); - vector.setVisible(false); - }; - client.onload = function () { - if (client.status === 200) { - var xmlDoc = $.parseXML(client.responseText), - xml = $(xmlDoc), - remark = xml.find('remark'), - nodosLength = xml.find('node').length; - - if (remark.length !== 0) { - console.error('Error:', remark.text()); - $('
').html(remark.text()).dialog({ - modal: true, - title: 'Error', - close: function () { - $(this).dialog('destroy'); - } - }); - client.onerror.call(this); - } else { - console.log('Nodes Found:', nodosLength); - if (nodosLength === 0) { - $('
').html(config.i18n.noNodesFound).dialog({ - modal: true, - //title: 'Error', - close: function () { - $(this).dialog('destroy'); - } - }); - } - var features = new ol.format.OSMXML2().readFeatures(xmlDoc, { - featureProjection: map.getView().getProjection() - }); - me.addFeatures(features); - } - } else { - client.onerror.call(this); - } - }; - client.send(query); - }, - strategy: ol.loadingstrategy.bbox - }); vectorProperties['source'] = vectorSource; vectorProperties['visible'] = false; From 0b4a2a9a9a2e8c4cab7f08953a01687a7fbbe810 Mon Sep 17 00:00:00 2001 From: yopaseopor Date: Sat, 12 Dec 2020 00:33:45 +0100 Subject: [PATCH 2/2] Update config.js --- src/config.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/config.js b/src/config.js index 989e738..e10638f 100644 --- a/src/config.js +++ b/src/config.js @@ -1036,6 +1036,21 @@ var config = { group: 'Test', title: 'node[name=]', query: 'node[name=]({{bbox}});out meta;' + }, + { + group: 'Test', + title: 'Stops signs at geojson', + geojson: 'https://raw.githubusercontent.com/yopaseopor/osmhistoricmap/master/src/img/base/test.geojson', + iconSrc: 'https://raw.githubusercontent.com/yopaseopor/beta_preset_josm/master/ES/traffic_signs/ES/ES_R2.png', + style: function () { + var style = new ol.style.Style({ + image: new ol.style.Icon({ + scale: 0.4, + src: 'https://raw.githubusercontent.com/yopaseopor/beta_preset_josm/master/ES/traffic_signs/ES/ES_R2.png' + }) + }); + return style; + } }, { group: 'Test',