Commit b0b8a9137e71c4aae3e8fe9683ea237bbaded2b8
1 parent
b3137645
plugin update
Showing
2 changed files
with
20 additions
and
10 deletions
datalets/leafletjs-datalet/demo/index.html
... | ... | @@ -13,8 +13,8 @@ |
13 | 13 | <script src="https://code.jquery.com/jquery-2.1.4.min.js" type="text/javascript"></script> |
14 | 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&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&limit=99999" selectedfields="[{"field":"Latitude","value":"Lat","index":1},{"field":"Longitude","value":"Lng","index":2},{"field":"BalloonContent","value":"Link","index":3}]" filters="[]" aggregators="[]" orders="[]" data="" fields="["Lat","Lng","Link"]"> | |
17 | + </leafletjs-datalet> | |
18 | 18 | |
19 | 19 | |
20 | 20 | </body> | ... | ... |
datalets/leafletjs-datalet/leafletjs-datalet.html
... | ... | @@ -91,6 +91,7 @@ Example: |
91 | 91 | var coordinates = []; |
92 | 92 | var coordinates_index = 0; |
93 | 93 | var isArray = t.data[0].data[0].constructor === Array; |
94 | + var geo; | |
94 | 95 | |
95 | 96 | for(var i=0; i<t.data[0].data.length; i++) |
96 | 97 | { |
... | ... | @@ -101,25 +102,34 @@ Example: |
101 | 102 | else |
102 | 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 | 113 | else if(typeof t.data[0].data[i] == 'string' && t.data[0].data[i].indexOf(",")) |
105 | 114 | { |
106 | 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 | 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 | 121 | continue; |
111 | 122 | } |
112 | 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 | 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 | 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 | 133 | if(t.data.length > 2) |
124 | 134 | { |
125 | 135 | var popupText = ""; |
... | ... | @@ -135,7 +145,7 @@ Example: |
135 | 145 | } |
136 | 146 | |
137 | 147 | var popup = L.popup().setContent(popupText); |
138 | - marker.bindPopup(popup); | |
148 | + geo.bindPopup(popup); | |
139 | 149 | } |
140 | 150 | } |
141 | 151 | ... | ... |