1 | {combine_script id="jquery.ui" path="themes/default/js/ui/minified/jquery.ui.core.min.js"} |
---|
2 | {combine_script id="jquery.ui.dialog" path="themes/default/js/ui/minified/jquery.ui.dialog.min.js"} |
---|
3 | {combine_script id="maps.google.com/api" path="http://maps.google.com/maps/api/js?sensor=false"} |
---|
4 | |
---|
5 | |
---|
6 | {literal} |
---|
7 | <script type="text/javascript"> |
---|
8 | |
---|
9 | /** |
---|
10 | * include this template in a page and use dialogChooseGMapsBox.show({options}) to display |
---|
11 | * the dialog box |
---|
12 | * |
---|
13 | */ |
---|
14 | dialogChooseGMapsBox = function() |
---|
15 | { |
---|
16 | var bounds = { |
---|
17 | north:0, |
---|
18 | south:0, |
---|
19 | east:0, |
---|
20 | west:0 |
---|
21 | }, |
---|
22 | requestId = '', |
---|
23 | callId=0, |
---|
24 | dialogGMapsOptions = { |
---|
25 | id:'', |
---|
26 | eventOk:null, |
---|
27 | cBuilder:null, |
---|
28 | gMap:null, |
---|
29 | }; |
---|
30 | |
---|
31 | |
---|
32 | /** |
---|
33 | * initialize the dialog box |
---|
34 | */ |
---|
35 | var initDialogBox = function() |
---|
36 | { |
---|
37 | initializeMap(); |
---|
38 | |
---|
39 | $.ajax( |
---|
40 | { |
---|
41 | type: "POST", |
---|
42 | url: "plugins/GMaps/gmaps_ajax.php", |
---|
43 | async: true, |
---|
44 | data: { ajaxfct:"public.maps.init", category:0 }, |
---|
45 | success: function (msg) |
---|
46 | { |
---|
47 | requestId=msg; |
---|
48 | } |
---|
49 | } |
---|
50 | ); |
---|
51 | |
---|
52 | $("#iDialogGMapsChoose") |
---|
53 | .dialog( |
---|
54 | { |
---|
55 | autoOpen: false, |
---|
56 | resizable: false, |
---|
57 | width:$(window).width()*0.8, |
---|
58 | height:$(window).height()*0.8, |
---|
59 | modal: true, |
---|
60 | draggable:true, |
---|
61 | dialogClass: 'gcBgTabSheet gcBorder', |
---|
62 | title: '{/literal}{"gmaps_choose_geographic_area"|@translate}{literal}', |
---|
63 | open: function(event, ui) |
---|
64 | { |
---|
65 | google.maps.event.trigger(dialogGMapsOptions.gMap, 'resize'); |
---|
66 | |
---|
67 | if(bounds.north!=0 && bounds.south!=0 && bounds.east!=0 && bounds.west!=0) |
---|
68 | { |
---|
69 | dialogGMapsOptions.gMap.fitBounds( |
---|
70 | new google.maps.LatLngBounds( |
---|
71 | new google.maps.LatLng(bounds.south, bounds.west), |
---|
72 | new google.maps.LatLng(bounds.north, bounds.east) |
---|
73 | ) |
---|
74 | ); |
---|
75 | } |
---|
76 | else |
---|
77 | { |
---|
78 | dialogGMapsOptions.gMap.setZoom(2); |
---|
79 | dialogGMapsOptions.gMap.setCenter(new google.maps.LatLng(0, 0)); |
---|
80 | updateBounds(); |
---|
81 | } |
---|
82 | |
---|
83 | loadMarkers(); |
---|
84 | }, |
---|
85 | buttons: |
---|
86 | { |
---|
87 | '{/literal}{"gmaps_ok"|@translate}{literal}': |
---|
88 | function() |
---|
89 | { |
---|
90 | updateBounds(); |
---|
91 | |
---|
92 | if(dialogGMapsOptions.cBuilder!=null) |
---|
93 | { |
---|
94 | setCBuilderItem(dialogGMapsOptions.id, bounds, requestId); |
---|
95 | } |
---|
96 | |
---|
97 | if(dialogGMapsOptions.eventOk!=null) |
---|
98 | { |
---|
99 | dialogGMapsOptions.eventOk(dialogGMapsOptions.id, bounds, requestId); |
---|
100 | } |
---|
101 | |
---|
102 | |
---|
103 | $(this).dialog('close'); |
---|
104 | }, |
---|
105 | '{/literal}{"gmaps_cancel"|@translate}{literal}': |
---|
106 | function() |
---|
107 | { |
---|
108 | $(this).dialog('close'); |
---|
109 | } |
---|
110 | } |
---|
111 | } |
---|
112 | ); |
---|
113 | |
---|
114 | } |
---|
115 | |
---|
116 | |
---|
117 | /** |
---|
118 | * initialize the map |
---|
119 | */ |
---|
120 | var initializeMap = function () |
---|
121 | { |
---|
122 | var latlng=new google.maps.LatLng(0, 0); |
---|
123 | |
---|
124 | var map = new google.maps.Map($("#iDialogGMapsMap").get(0), |
---|
125 | { |
---|
126 | mapTypeId:google.maps.MapTypeId.HYBRID, |
---|
127 | zoom:2, |
---|
128 | center:latlng, |
---|
129 | navigationControl: true, |
---|
130 | navigationControlOptions: |
---|
131 | { |
---|
132 | style:google.maps.NavigationControlStyle.ZOOM_PAN, |
---|
133 | }, |
---|
134 | scaleControl: true, |
---|
135 | streetViewControl: false, |
---|
136 | mapTypeControl:true, |
---|
137 | mapTypeControlOptions: |
---|
138 | { |
---|
139 | style:google.maps.MapTypeControlStyle.DROPDOWN_MENU, |
---|
140 | }, |
---|
141 | markerTitle:'', |
---|
142 | } |
---|
143 | ); |
---|
144 | |
---|
145 | map.markers=new Array(); |
---|
146 | dialogGMapsOptions.gMap=map; |
---|
147 | |
---|
148 | google.maps.event.addListener( |
---|
149 | dialogGMapsOptions.gMap, |
---|
150 | 'dragend', |
---|
151 | function() |
---|
152 | { |
---|
153 | updateBounds(); |
---|
154 | loadMarkers(); |
---|
155 | } |
---|
156 | ); |
---|
157 | |
---|
158 | google.maps.event.addListener( |
---|
159 | dialogGMapsOptions.gMap, |
---|
160 | 'zoom_changed', |
---|
161 | function() |
---|
162 | { |
---|
163 | updateBounds(); |
---|
164 | loadMarkers(); |
---|
165 | } |
---|
166 | ); |
---|
167 | } |
---|
168 | |
---|
169 | |
---|
170 | /** |
---|
171 | * update the bounds properties from the map bounds |
---|
172 | */ |
---|
173 | var updateBounds = function () |
---|
174 | { |
---|
175 | var mapBounds=dialogGMapsOptions.gMap.getBounds(); |
---|
176 | bounds.north=mapBounds.getNorthEast().lat(); |
---|
177 | bounds.south=mapBounds.getSouthWest().lat(); |
---|
178 | bounds.east=mapBounds.getNorthEast().lng(); |
---|
179 | bounds.west=mapBounds.getSouthWest().lng(); |
---|
180 | } |
---|
181 | |
---|
182 | /** |
---|
183 | * set the request Id |
---|
184 | */ |
---|
185 | var setRequestId = function(msg) |
---|
186 | { |
---|
187 | dialogGMapsOptions.requestId=msg; |
---|
188 | requestId=msg; |
---|
189 | dialogGMapsOptions.requestId=msg; |
---|
190 | } |
---|
191 | |
---|
192 | |
---|
193 | /** |
---|
194 | * load markers from the server |
---|
195 | */ |
---|
196 | var loadMarkers = function () |
---|
197 | { |
---|
198 | callId++; |
---|
199 | |
---|
200 | datas={ |
---|
201 | requestId:requestId, |
---|
202 | callId:callId, |
---|
203 | bounds:{ |
---|
204 | north:bounds.north, |
---|
205 | east:bounds.east, |
---|
206 | south:bounds.south, |
---|
207 | west:bounds.west |
---|
208 | }, |
---|
209 | width:$(dialogGMapsOptions.gMap.getDiv()).width(), |
---|
210 | height:$(dialogGMapsOptions.gMap.getDiv()).height(), |
---|
211 | distanceTreshold:20, |
---|
212 | levelInfo:0 |
---|
213 | } |
---|
214 | |
---|
215 | $('#iDialogGMapNfo').html('<img src="./plugins/GrumPluginClasses/icons/processing.gif"><span>{/literal}{"gmaps_loading"|@translate}{literal}</span>'); |
---|
216 | |
---|
217 | $.ajax( |
---|
218 | { |
---|
219 | type: "POST", |
---|
220 | url: "plugins/GMaps/gmaps_ajax.php", |
---|
221 | async: true, |
---|
222 | data: { ajaxfct:"public.maps.getMarkers", datas:datas }, |
---|
223 | success: |
---|
224 | function(msg) |
---|
225 | { |
---|
226 | tmp=$.parseJSON(msg); |
---|
227 | if(tmp.callId==callId) |
---|
228 | { |
---|
229 | tmp.markers.sort(compareMarkers); |
---|
230 | applyMarkers(tmp.markers); |
---|
231 | $('#iDialogGMapNfo').html(tmp.datas.nbPhotos); |
---|
232 | } |
---|
233 | } |
---|
234 | } |
---|
235 | ); |
---|
236 | } |
---|
237 | |
---|
238 | /** |
---|
239 | * apply markers to map |
---|
240 | * |
---|
241 | * @param Array markers : array of markers properties |
---|
242 | * each marker is an object with properties : |
---|
243 | * latitude, longitude, nbImages |
---|
244 | */ |
---|
245 | function applyMarkers(markers) |
---|
246 | { |
---|
247 | /* |
---|
248 | * deleting markers from the map only if they are not in the new list |
---|
249 | */ |
---|
250 | if(dialogGMapsOptions.gMap.markers.length>0) |
---|
251 | { |
---|
252 | var i=0; |
---|
253 | while(i<dialogGMapsOptions.gMap.markers.length) |
---|
254 | { |
---|
255 | newListIndex=markerInList(dialogGMapsOptions.gMap.markers[i].uId, markers); |
---|
256 | if(newListIndex==-1) |
---|
257 | { |
---|
258 | dialogGMapsOptions.gMap.markers[i].marker.setMap(null); |
---|
259 | dialogGMapsOptions.gMap.markers.splice(i, 1); |
---|
260 | } |
---|
261 | else |
---|
262 | { |
---|
263 | markers.splice(newListIndex,1); |
---|
264 | i++; |
---|
265 | } |
---|
266 | } |
---|
267 | } |
---|
268 | |
---|
269 | /* |
---|
270 | * add new markers on the map |
---|
271 | */ |
---|
272 | for(var i=0;i<markers.length;i++) |
---|
273 | { |
---|
274 | var marker = new google.maps.Marker( |
---|
275 | { |
---|
276 | position:new google.maps.LatLng(markers[i].lat, markers[i].lng), |
---|
277 | map: dialogGMapsOptions.gMap, |
---|
278 | title:markers[i].nbImgTxt |
---|
279 | } |
---|
280 | ); |
---|
281 | |
---|
282 | marker.info=markers[i]; |
---|
283 | marker.info.displayed=0; |
---|
284 | |
---|
285 | dialogGMapsOptions.gMap.markers.push( |
---|
286 | { |
---|
287 | marker:marker, |
---|
288 | uId:markers[i].uId |
---|
289 | } |
---|
290 | ); |
---|
291 | } |
---|
292 | } |
---|
293 | |
---|
294 | function compareMarkers(m1,m2) |
---|
295 | { |
---|
296 | if(m1.uId<m2.uId) |
---|
297 | { |
---|
298 | return(-1); |
---|
299 | } |
---|
300 | else if(m1.uId<m2.uId) |
---|
301 | { |
---|
302 | return(1); |
---|
303 | } |
---|
304 | return(0); |
---|
305 | } |
---|
306 | |
---|
307 | function markerInList(uId, markerList) |
---|
308 | { |
---|
309 | for(var i=0;i<markerList.length;i++) |
---|
310 | { |
---|
311 | if(markerList[i].uId==uId) return(i) |
---|
312 | } |
---|
313 | return(-1); |
---|
314 | } |
---|
315 | |
---|
316 | |
---|
317 | /** |
---|
318 | * the show() function display and manage a dialog box to choose |
---|
319 | * a geographic area |
---|
320 | * |
---|
321 | * @param options : properties to manage the dialog box |
---|
322 | * - bounds : an object with properties 'north', 'south', 'east' |
---|
323 | * and 'west' |
---|
324 | * - id : a string to identify a DOM object ; this parameter |
---|
325 | * is given to the callback when the OK button is pushed |
---|
326 | * - eventOK : a callback function, with 2 parameters : id of |
---|
327 | * the given DOM object and the bounds object |
---|
328 | * - cBuilder : a criteriaBuilder object |
---|
329 | * if set, the dialog box manage automaticaly |
---|
330 | * the criteria builder interface |
---|
331 | */ |
---|
332 | this.show = function (options) |
---|
333 | { |
---|
334 | showDialog(options); |
---|
335 | } |
---|
336 | |
---|
337 | /** |
---|
338 | * private function used to show the dialog box |
---|
339 | */ |
---|
340 | var showDialog = function(options) |
---|
341 | { |
---|
342 | if(options.bounds!=null) |
---|
343 | { |
---|
344 | bounds=options.bounds; |
---|
345 | } |
---|
346 | else |
---|
347 | { |
---|
348 | bounds={ |
---|
349 | north:0, |
---|
350 | south:0, |
---|
351 | east:0, |
---|
352 | west:0 |
---|
353 | }; |
---|
354 | } |
---|
355 | |
---|
356 | if(options.id!=null) |
---|
357 | { |
---|
358 | dialogGMapsOptions.id=options.id; |
---|
359 | } |
---|
360 | else |
---|
361 | { |
---|
362 | dialogGMapsOptions.id=''; |
---|
363 | } |
---|
364 | |
---|
365 | if(options.eventOk!=null) |
---|
366 | { |
---|
367 | dialogGMapsOptions.eventOk=options.eventOk; |
---|
368 | } |
---|
369 | |
---|
370 | if(options.cBuilder!=null) |
---|
371 | { |
---|
372 | dialogGMapsOptions.cBuilder=options.cBuilder; |
---|
373 | dialogGMapsOptions.cBuilder.doAction('setOptions', |
---|
374 | { |
---|
375 | onEdit:function (e) { editGA(e.data); }, |
---|
376 | onDelete:function (e) { deleteGA(e.data); }, |
---|
377 | } |
---|
378 | ); |
---|
379 | } |
---|
380 | |
---|
381 | $("#iDialogGMapsChoose").dialog('open'); |
---|
382 | } |
---|
383 | |
---|
384 | |
---|
385 | |
---|
386 | /** |
---|
387 | * manage the 'edit' button from criteria builder interface |
---|
388 | * @param String itemId : the itemId |
---|
389 | */ |
---|
390 | var editGA = function (itemId) |
---|
391 | { |
---|
392 | extraData=dialogGMapsOptions.cBuilder.doAction('getExtraData', itemId); |
---|
393 | showDialog( |
---|
394 | { |
---|
395 | id:itemId, |
---|
396 | bounds:extraData.param.bounds, |
---|
397 | requestId:extraData.param.requestId |
---|
398 | } |
---|
399 | ); |
---|
400 | } |
---|
401 | |
---|
402 | /** |
---|
403 | * manage the 'delete' button from criteria builder interface |
---|
404 | * @param String itemId : the itemId |
---|
405 | */ |
---|
406 | var deleteGA = function (itemId) |
---|
407 | { |
---|
408 | dialogGMapsOptions.cBuilder.doAction('delete', itemId); |
---|
409 | } |
---|
410 | |
---|
411 | /** |
---|
412 | * set the content for the cBuilder item |
---|
413 | */ |
---|
414 | var setCBuilderItem = function(id, bounds) |
---|
415 | { |
---|
416 | |
---|
417 | var content="<div>{/literal}{'gmaps_geographic_coords_between'|@translate}{literal}<br>"; |
---|
418 | content+="<span style='margin-left:20px;'>• "+DDtoDMS(bounds.south)+" {/literal}{'gmaps_south'|@translate} {'gmaps_and'|@translate} "+DDtoDMS(bounds.north)+" {'gmaps_north'|@translate}{literal}</span><br>"; |
---|
419 | |
---|
420 | if(bounds.east<bounds.west) |
---|
421 | { |
---|
422 | content+="<span style='margin-left:20px;'>• "+DDtoDMS(bounds.east)+" {/literal}{'gmaps_east'|@translate} {'gmaps_and'|@translate} "+DDtoDMS(bounds.west)+" {'gmaps_west'|@translate}{literal}</span>"; |
---|
423 | } |
---|
424 | else |
---|
425 | { |
---|
426 | content+="<span style='margin-left:20px;'>• "+DDtoDMS(bounds.west)+" {/literal}{'gmaps_west'|@translate} {'gmaps_and'|@translate} "+DDtoDMS(bounds.east)+" {'gmaps_east'|@translate}{literal}</span>"; |
---|
427 | } |
---|
428 | content+="</div>"; |
---|
429 | |
---|
430 | |
---|
431 | if(id=='') |
---|
432 | { |
---|
433 | //no id:add a new item in the list |
---|
434 | dialogGMapsOptions.cBuilder.doAction('add', content, criteriaBuilder.makeExtendedData('GMaps', {bounds:$.extend({}, bounds), requestId:requestId } ) ); |
---|
435 | } |
---|
436 | else |
---|
437 | { |
---|
438 | // update item |
---|
439 | dialogGMapsOptions.cBuilder.doAction('edit', id, content, criteriaBuilder.makeExtendedData('GMaps', {bounds:$.extend({}, bounds), requestId:requestId } ) ); |
---|
440 | } |
---|
441 | } |
---|
442 | |
---|
443 | /** |
---|
444 | * convert a decimal degree to D°M'S' |
---|
445 | * note : negative values are converted in positive values, assuming North/South |
---|
446 | * and East/West are managed outside this function |
---|
447 | * |
---|
448 | * @param Float $value : the value to convert |
---|
449 | * @return String : value converted in DMS |
---|
450 | */ |
---|
451 | var DDtoDMS = function (value) |
---|
452 | { |
---|
453 | value=Math.abs(value); |
---|
454 | degrees=Math.floor(value); |
---|
455 | tmp=(value-degrees)*60; |
---|
456 | minutes=Math.floor(tmp); |
---|
457 | seconds=Math.round((tmp-minutes)*6000)/100; |
---|
458 | return(degrees+"° "+minutes+"' "+seconds+'"'); |
---|
459 | } |
---|
460 | |
---|
461 | initDialogBox(); |
---|
462 | } |
---|
463 | |
---|
464 | |
---|
465 | </script> |
---|
466 | {/literal} |
---|
467 | |
---|
468 | <div id="iDialogGMapsChoose" style='display:none;'> |
---|
469 | <div id='iDialogGMapNfo'> </div> |
---|
470 | <div id='iDialogGMapsMap' style='width:95%; height:95%;margin-left:auto;margin-right:auto;border:1px solid;'></div> |
---|
471 | </div> |
---|
472 | |
---|
473 | |
---|