Commit 7fb2403bc52ce7c009b2e109238d5d220b3bca23

Authored by Renato De Donato
2 parents 2e94028d 1bf9f64c

Merge branch 'master' of http://service.routetopa.eu:7480/WebCompDev/COMPONENTS

datalets/leafletjs-geojson-datalet/leafletjs-geojson-datalet.html
... ... @@ -89,34 +89,43 @@ Example:
89 89  
90 90 L.Icon.Default.imagePath = 'http://services.routetopa.eu/DEEalerProvider/COMPONENTS/datalets/leafletjs-datalet/leafletsjs/images';
91 91  
92   - var coordinates = [];
93   - var coordinates_index = 0;
  92 + //var coordinates = [];
  93 + //var coordinates_index = 0;
  94 + var geo_layer = L.geoJson();
94 95 var geo;
95 96  
96 97 for (var i = 0; i < t.data[0].data.length; i++)
97 98 {
98   - if(typeof t.data[0].data[0] == 'Array')
  99 + if(Array.isArray(t.data[0].data[i]))
99 100 {
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
  101 + if(!isNaN(t.data[0].data[i][0]) && !isNaN(t.data[0].data[i][1])) {
  102 + //coordinates.push([parseFloat(t.data[0].data[i][0]), parseFloat(t.data[0].data[i][1])]);
  103 + geo_layer.addData({"type": "Feature","geometry": {"type": "Point", "coordinates": [parseFloat(t.data[0].data[i][0]), parseFloat(t.data[0].data[i][1])]}});
  104 + }else
103 105 continue;
104 106 }
  107 + else if(typeof t.data[0].data[i] == 'object')
  108 + {
  109 + geo = L.geoJson(t.data[0].data[i]).addTo(t._component.map);
  110 + geo_layer.addData(t.data[0].data[i]);
  111 + }
105 112 else if(typeof t.data[0].data[i] == 'string' && t.data[0].data[i].startsWith('{"type":"'))
106 113 {
107 114 try
108 115 {
109 116 t.data[0].data[i] = JSON.parse(t.data[0].data[i]);
110 117 geo = L.geoJson(t.data[0].data[i]).addTo(t._component.map);
  118 + geo_layer.addData(t.data[0].data[i]);
111 119 }catch(e) {continue;}
112 120 }
113 121 else if(typeof t.data[0].data[i] == 'string' && t.data[0].data[i].indexOf(","))
114 122 {
115 123 var coords = t.data[0].data[i].split(",");
116 124 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++;
  125 + //coordinates.push([parseFloat(coords[0]), parseFloat(coords[1])]);
  126 + geo_layer.addData({"type": "Feature","geometry": {"type": "Point", "coordinates": [parseFloat(coords[0]), parseFloat(coords[1])]}});
  127 + geo = L.marker([parseFloat(coords[0]), parseFloat(coords[1])]).addTo(t._component.map);
  128 + //coordinates_index++;
120 129 }else
121 130 continue;
122 131 }
... ... @@ -142,7 +151,7 @@ Example:
142 151  
143 152 t._component.map._onResize();
144 153 t._component.map.invalidateSize(false);
145   - t._component.map.fitBounds(coordinates);
  154 + t._component.map.fitBounds(geo_layer);
146 155  
147 156 }
148 157 };
... ...