Commit b0b8a9137e71c4aae3e8fe9683ea237bbaded2b8

Authored by Andrea Petta
1 parent b3137645

plugin update

datalets/leafletjs-datalet/demo/index.html
@@ -13,8 +13,8 @@ @@ -13,8 +13,8 @@
13 <script src="https://code.jquery.com/jquery-2.1.4.min.js" type="text/javascript"></script> 13 <script src="https://code.jquery.com/jquery-2.1.4.min.js" type="text/javascript"></script>
14 <link rel="import" href="../leafletjs-datalet.html" /> 14 <link rel="import" href="../leafletjs-datalet.html" />
15 15
16 -<leafletjs-datalet data-url="http://ckan.routetopa.eu/api/action/datastore_search?resource_id=73e02092-85a1-434e-85fe-0c9a43aa9a52&amp;limit=10000"  
17 - fields='["result,records,Lat","result,records,Lng", "result,records,Link"]'></leafletjs-datalet> 16 +<leafletjs-datalet data-url="http://ckan.routetopa.eu/api/action/datastore_search?resource_id=73e02092-85a1-434e-85fe-0c9a43aa9a52&amp;limit=99999" selectedfields="[{&quot;field&quot;:&quot;Latitude&quot;,&quot;value&quot;:&quot;Lat&quot;,&quot;index&quot;:1},{&quot;field&quot;:&quot;Longitude&quot;,&quot;value&quot;:&quot;Lng&quot;,&quot;index&quot;:2},{&quot;field&quot;:&quot;BalloonContent&quot;,&quot;value&quot;:&quot;Link&quot;,&quot;index&quot;:3}]" filters="[]" aggregators="[]" orders="[]" data="" fields="[&quot;Lat&quot;,&quot;Lng&quot;,&quot;Link&quot;]">
  17 + </leafletjs-datalet>
18 18
19 19
20 </body> 20 </body>
datalets/leafletjs-datalet/leafletjs-datalet.html
@@ -91,6 +91,7 @@ Example: @@ -91,6 +91,7 @@ Example:
91 var coordinates = []; 91 var coordinates = [];
92 var coordinates_index = 0; 92 var coordinates_index = 0;
93 var isArray = t.data[0].data[0].constructor === Array; 93 var isArray = t.data[0].data[0].constructor === Array;
  94 + var geo;
94 95
95 for(var i=0; i<t.data[0].data.length; i++) 96 for(var i=0; i<t.data[0].data.length; i++)
96 { 97 {
@@ -101,25 +102,34 @@ Example: @@ -101,25 +102,34 @@ Example:
101 else 102 else
102 continue; 103 continue;
103 } 104 }
  105 + else if(typeof t.data[0].data[i] == 'string' && t.data[0].data[i].startsWith('{"type":"'))
  106 + {
  107 + try
  108 + {
  109 + t.data[0].data[i] = JSON.parse(t.data[0].data[i]);
  110 + geo = L.geoJson(t.data[0].data[i]).addTo(t._component.map);
  111 + }catch(e) {continue;}
  112 + }
104 else if(typeof t.data[0].data[i] == 'string' && t.data[0].data[i].indexOf(",")) 113 else if(typeof t.data[0].data[i] == 'string' && t.data[0].data[i].indexOf(","))
105 { 114 {
106 var coords = t.data[0].data[i].split(","); 115 var coords = t.data[0].data[i].split(",");
107 - if(!isNaN(coords[0]) && !isNaN(coords[1])) 116 + if(!isNaN(coords[0]) && !isNaN(coords[1])) {
108 coordinates.push([parseFloat(coords[0]), parseFloat(coords[1])]); 117 coordinates.push([parseFloat(coords[0]), parseFloat(coords[1])]);
109 - else 118 + geo = L.marker([coordinates[coordinates_index][0], coordinates[coordinates_index][1]]).addTo(t._component.map);
  119 + coordinates_index++;
  120 + }else
110 continue; 121 continue;
111 } 122 }
112 else 123 else
113 { 124 {
114 - if(!isNaN(t.data[0].data[i]) && !isNaN(t.data[1].data[i])) 125 + if(!isNaN(t.data[0].data[i]) && !isNaN(t.data[1].data[i])) {
115 coordinates.push([parseFloat(t.data[0].data[i]), parseFloat(t.data[1].data[i])]); 126 coordinates.push([parseFloat(t.data[0].data[i]), parseFloat(t.data[1].data[i])]);
116 - else 127 + geo = L.marker([coordinates[coordinates_index][0], coordinates[coordinates_index][1]]).addTo(t._component.map);
  128 + coordinates_index++;
  129 + }else
117 continue; 130 continue;
118 } 131 }
119 132
120 - var marker = L.marker([coordinates[coordinates_index][0], coordinates[coordinates_index][1]]).addTo(t._component.map);  
121 - coordinates_index++;  
122 -  
123 if(t.data.length > 2) 133 if(t.data.length > 2)
124 { 134 {
125 var popupText = ""; 135 var popupText = "";
@@ -135,7 +145,7 @@ Example: @@ -135,7 +145,7 @@ Example:
135 } 145 }
136 146
137 var popup = L.popup().setContent(popupText); 147 var popup = L.popup().setContent(popupText);
138 - marker.bindPopup(popup); 148 + geo.bindPopup(popup);
139 } 149 }
140 } 150 }
141 151