From ddeadce5082d6391f500446b495814aa8d06387b Mon Sep 17 00:00:00 2001 From: andrpet Date: Mon, 25 Jul 2016 15:33:03 +0200 Subject: [PATCH] plugin update --- datalets/leafletjs-geojson-datalet/leafletjs-geojson-datalet.html | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/datalets/leafletjs-geojson-datalet/leafletjs-geojson-datalet.html b/datalets/leafletjs-geojson-datalet/leafletjs-geojson-datalet.html index d3c990f..9bdb7c4 100755 --- a/datalets/leafletjs-geojson-datalet/leafletjs-geojson-datalet.html +++ b/datalets/leafletjs-geojson-datalet/leafletjs-geojson-datalet.html @@ -89,34 +89,43 @@ Example: L.Icon.Default.imagePath = 'http://services.routetopa.eu/DEEalerProvider/COMPONENTS/datalets/leafletjs-datalet/leafletsjs/images'; - var coordinates = []; - var coordinates_index = 0; + //var coordinates = []; + //var coordinates_index = 0; + var geo_layer = L.geoJson(); var geo; for (var i = 0; i < t.data[0].data.length; i++) { - if(typeof t.data[0].data[0] == 'Array') + if(Array.isArray(t.data[0].data[i])) { - if(!isNaN(t.data[0].data[i][0]) && !isNaN(t.data[0].data[i][1])) - coordinates.push([parseFloat(t.data[0].data[i][0]), parseFloat(t.data[0].data[i][1])]); - else + if(!isNaN(t.data[0].data[i][0]) && !isNaN(t.data[0].data[i][1])) { + //coordinates.push([parseFloat(t.data[0].data[i][0]), parseFloat(t.data[0].data[i][1])]); + geo_layer.addData({"type": "Feature","geometry": {"type": "Point", "coordinates": [parseFloat(t.data[0].data[i][0]), parseFloat(t.data[0].data[i][1])]}}); + }else continue; } + else if(typeof t.data[0].data[i] == 'object') + { + geo = L.geoJson(t.data[0].data[i]).addTo(t._component.map); + geo_layer.addData(t.data[0].data[i]); + } else if(typeof t.data[0].data[i] == 'string' && t.data[0].data[i].startsWith('{"type":"')) { try { t.data[0].data[i] = JSON.parse(t.data[0].data[i]); geo = L.geoJson(t.data[0].data[i]).addTo(t._component.map); + geo_layer.addData(t.data[0].data[i]); }catch(e) {continue;} } else if(typeof t.data[0].data[i] == 'string' && t.data[0].data[i].indexOf(",")) { var coords = t.data[0].data[i].split(","); if(!isNaN(coords[0]) && !isNaN(coords[1])) { - coordinates.push([parseFloat(coords[0]), parseFloat(coords[1])]); - geo = L.marker([coordinates[coordinates_index][0], coordinates[coordinates_index][1]]).addTo(t._component.map); - coordinates_index++; + //coordinates.push([parseFloat(coords[0]), parseFloat(coords[1])]); + geo_layer.addData({"type": "Feature","geometry": {"type": "Point", "coordinates": [parseFloat(coords[0]), parseFloat(coords[1])]}}); + geo = L.marker([parseFloat(coords[0]), parseFloat(coords[1])]).addTo(t._component.map); + //coordinates_index++; }else continue; } @@ -142,7 +151,7 @@ Example: t._component.map._onResize(); t._component.map.invalidateSize(false); - t._component.map.fitBounds(coordinates); + t._component.map.fitBounds(geo_layer); } }; -- libgit2 0.21.4