Commit 88657b89a5553e4fcffe2f0f13498c51adf8d48b

Authored by Andrea Petta
1 parent 37bd0ebd

plugin update

datalets/leafletjs-geojson-datalet/leafletjs-geojson-datalet.html
@@ -89,16 +89,37 @@ Example: @@ -89,16 +89,37 @@ Example:
89 89
90 L.Icon.Default.imagePath = 'http://services.routetopa.eu/DEEalerProvider/COMPONENTS/datalets/leafletjs-datalet/leafletsjs/images'; 90 L.Icon.Default.imagePath = 'http://services.routetopa.eu/DEEalerProvider/COMPONENTS/datalets/leafletjs-datalet/leafletsjs/images';
91 91
92 - var bounding_box = L.geoJson(t.data[0].data); 92 + var coordinates = [];
  93 + var coordinates_index = 0;
  94 + var geo;
93 95
94 for (var i = 0; i < t.data[0].data.length; i++) 96 for (var i = 0; i < t.data[0].data.length; i++)
95 { 97 {
96 - try{  
97 - if(typeof t.data[0].data[i] != 'object') 98 + if(typeof t.data[0].data[0] == 'Array')
  99 + {
  100 + if(!isNaN(t.data[0].data[i][0]) && !isNaN(t.data[0].data[i][1]))
  101 + coordinates.push([parseFloat(t.data[0].data[i][0]), parseFloat(t.data[0].data[i][1])]);
  102 + else
  103 + continue;
  104 + }
  105 + else if(typeof t.data[0].data[i] == 'string' && t.data[0].data[i].startsWith('{"type":"'))
  106 + {
  107 + try
  108 + {
98 t.data[0].data[i] = JSON.parse(t.data[0].data[i]); 109 t.data[0].data[i] = JSON.parse(t.data[0].data[i]);
99 - }catch(e){}  
100 -  
101 - var geoJsonLayer = L.geoJson(t.data[0].data[i]).addTo(t._component.map); 110 + geo = L.geoJson(t.data[0].data[i]).addTo(t._component.map);
  111 + }catch(e) {continue;}
  112 + }
  113 + else if(typeof t.data[0].data[i] == 'string' && t.data[0].data[i].indexOf(","))
  114 + {
  115 + var coords = t.data[0].data[i].split(",");
  116 + if(!isNaN(coords[0]) && !isNaN(coords[1])) {
  117 + coordinates.push([parseFloat(coords[0]), parseFloat(coords[1])]);
  118 + geo = L.marker([coordinates[coordinates_index][0], coordinates[coordinates_index][1]]).addTo(t._component.map);
  119 + coordinates_index++;
  120 + }else
  121 + continue;
  122 + }
102 123
103 if(t.data.length > 1) 124 if(t.data.length > 1)
104 { 125 {
@@ -115,13 +136,13 @@ Example: @@ -115,13 +136,13 @@ Example:
115 } 136 }
116 137
117 var popup = L.popup().setContent(popupText); 138 var popup = L.popup().setContent(popupText);
118 - geoJsonLayer.bindPopup(popup); 139 + geo.bindPopup(popup);
119 } 140 }
120 } 141 }
121 142
122 t._component.map._onResize(); 143 t._component.map._onResize();
123 t._component.map.invalidateSize(false); 144 t._component.map.invalidateSize(false);
124 - t._component.map.fitBounds(bounding_box); 145 + t._component.map.fitBounds(coordinates);
125 146
126 } 147 }
127 }; 148 };