Commit 80d6c279cf2b92b6d3531e24c61d0774c2fe6f9d

Authored by Renato De Donato
2 parents d8eb088e 88657b89

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

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
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 };