1: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
2:
3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15:
16: class Googlemaps {
17:
18: var $adsense = FALSE;
19: var $adsenseChannelNumber = '';
20: var $adsenseFormat = 'HALF_BANNER';
21: var $adsensePosition = 'TOP_CENTER';
22: var $adsensePublisherID = '';
23: var $apiKey = '';
24: var $backgroundColor = '';
25: var $bicyclingOverlay = FALSE;
26: var $center = "37.4419, -122.1419";
27: var $cluster = FALSE;
28: var $clusterGridSize = 60;
29: var $clusterMaxZoom = '';
30: var $clusterZoomOnClick = TRUE;
31: var $clusterAverageCenter = FALSE;
32: var $clusterMinimumClusterSize = 2;
33: var $disableDefaultUI = FALSE;
34: var $disableDoubleClickZoom = FALSE;
35: var $disableMapTypeControl = FALSE;
36: var $disableNavigationControl = FALSE;
37: var $disableScaleControl = FALSE;
38: var $disableStreetViewControl = FALSE;
39: var $draggable = TRUE;
40: var $draggableCursor = '';
41: var $draggingCursor = '';
42: var $geocodeCaching = FALSE;
43: var $https = FALSE;
44: var $navigationControlPosition = '';
45: var $keyboardShortcuts = TRUE;
46: var $jsfile = '';
47: var $kmlLayerURL = '';
48: var $kmlLayerPreserveViewport = FALSE;
49: var $language = '';
50: var $loadAsynchronously = FALSE;
51: var $map_div_id = "map_canvas";
52: var $map_height = "450px";
53: var $map_name = "map";
54: var $map_type = "ROADMAP";
55: var $map_types_available = array();
56: var $map_width = "100%";
57: var $mapTypeControlPosition = '';
58: var $mapTypeControlStyle = '';
59: var $minzoom = '';
60: var $maxzoom = '';
61: var $minifyJS = FALSE;
62: var $noClear = FALSE;
63: var $onboundschanged = '';
64: var $oncenterchanged = '';
65: var $onclick = '';
66: var $ondblclick = '';
67: var $ondrag = '';
68: var $ondragend = '';
69: var $ondragstart = '';
70: var $onidle = '';
71: var $onload = '';
72: var $onmousemove = '';
73: var $onmouseout = '';
74: var $onmouseover = '';
75: var $onresize = '';
76: var $onrightclick = '';
77: var $ontilesloaded = '';
78: var $onzoomchanged = '';
79: var $panoramio = FALSE;
80: var $panoramioTag = '';
81: var $panoramioUser = '';
82: var $region = '';
83: var $scaleControlPosition = '';
84: var $scrollwheel = TRUE;
85: var $sensor = FALSE;
86: var $streetViewAddressControl = TRUE;
87: var $streetViewAddressPosition = '';
88: var $streetViewControlPosition = '';
89: var $streetViewCloseButton = FALSE;
90: var $streetViewLinksControl = TRUE;
91: var $streetViewPanControl = TRUE;
92: var $streetViewPanPosition = '';
93: var $streetViewPovHeading = 0;
94: var $streetViewPovPitch = 0;
95: var $streetViewPovZoom = 0;
96: var $streetViewZoomControl = TRUE;
97: var $streetViewZoomPosition = '';
98: var $streetViewZoomStyle = '';
99: var $styles = array();
100: var $stylesAsMapTypes = false;
101: var $stylesAsMapTypesDefault = '';
102: var $tilt = 0;
103: var $trafficOverlay = FALSE;
104: var $version = "3";
105: var $zoom = 13;
106: var $zoomControlPosition = '';
107: var $zoomControlStyle = '';
108:
109: var $markers = array();
110: var $markersInfo = array();
111: var $polylines = array();
112: var $polygons = array();
113: var $circles = array();
114: var $rectangles = array();
115: var $overlays = array();
116:
117: var $directions = FALSE;
118: var $directionsStart = "";
119: var $directionsEnd = "";
120: var $directionsDivID = "";
121: var $directionsMode = "DRIVING";
122: var $directionsAvoidTolls = FALSE;
123: var $directionsAvoidHighways = FALSE;
124: var $directionsDraggable = FALSE;
125: var $directionsChanged = "";
126: var $directionsUnits = "";
127:
128: var $drawing = FALSE;
129: var $drawingControl = TRUE;
130: var $drawingControlPosition = 'TOP_CENTER';
131: var $drawingDefaultMode = 'marker';
132: var $drawingModes = array();
133: var $drawingOnComplete = array();
134: var $drawingOnEdit = array();
135:
136: var $places = FALSE;
137: var $placesLocation = '';
138: var $placesRadius = 0;
139: var $placesLocationSW = '';
140: var $placesLocationNE = '';
141: var $placesTypes = array();
142: var $placesName = '';
143: var $placesAutocompleteInputID = '';
144: var $placesAutocompleteTypes = array();
145: var $placesAutocompleteBoundSW = '';
146: var $placesAutocompleteBoundNE = '';
147: var $placesAutocompleteBoundsMap= FALSE;
148: var $placesAutocompleteOnChange = '';
149:
150: function __construct($config = array())
151: {
152: if (count($config) > 0)
153: {
154: $this->initialize($config);
155: }
156:
157: log_message('debug', "Google Maps Class Initialized");
158: }
159:
160: function initialize($config = array())
161: {
162: foreach ($config as $key => $val)
163: {
164: if (isset($this->$key))
165: {
166: $this->$key = $val;
167: }
168: }
169:
170: if ($this->sensor) { $this->sensor = "true"; }else{ $this->sensor = "false"; }
171:
172: }
173:
174: function add_marker($params = array())
175: {
176:
177: $marker = array();
178: $this->markersInfo['marker_'.count($this->markers)] = array();
179:
180: $marker['position'] = '';
181: $marker['infowindow_content'] = '';
182: $marker['id'] = '';
183: $marker['clickable'] = TRUE;
184: $marker['cursor'] = '';
185: $marker['draggable'] = FALSE;
186: $marker['flat'] = FALSE;
187: $marker['icon'] = '';
188: $marker['animation'] = '';
189: $marker['onclick'] = '';
190: $marker['ondblclick'] = '';
191: $marker['ondrag'] = '';
192: $marker['ondragstart'] = '';
193: $marker['ondragend'] = '';
194: $marker['onmousedown'] = '';
195: $marker['onmouseout'] = '';
196: $marker['onmouseover'] = '';
197: $marker['onmouseup'] = '';
198: $marker['onpositionchanged'] = '';
199: $marker['onrightclick'] = '';
200: $marker['raiseondrag'] = TRUE;
201: $marker['shadow'] = '';
202: $marker['title'] = '';
203: $marker['visible'] = TRUE;
204: $marker['zIndex'] = '';
205:
206: $marker_output = '';
207:
208: foreach ($params as $key => $value) {
209:
210: if (isset($marker[$key])) {
211:
212: $marker[$key] = $value;
213:
214: }
215:
216: }
217:
218: $marker_id = count($this->markers);
219: if (trim($marker['id']) != "")
220: {
221: $marker_id = $marker['id'];
222: }
223:
224: if ($marker['position']!="") {
225: if ($this->is_lat_long($marker['position'])) {
226: $marker_output .= '
227: var myLatlng = new google.maps.LatLng('.$marker['position'].');
228: ';
229: $explodePosition = explode(",", $marker['position']);
230: $this->markersInfo['marker_'.$marker_id]['latitude'] = trim($explodePosition[0]);
231: $this->markersInfo['marker_'.$marker_id]['longitude'] = trim($explodePosition[1]);
232: }else{
233: $lat_long = $this->get_lat_long_from_address($marker['position']);
234: $marker_output .= '
235: var myLatlng = new google.maps.LatLng('.$lat_long[0].', '.$lat_long[1].');';
236: $this->markersInfo['marker_'.$marker_id]['latitude'] = $lat_long[0];
237: $this->markersInfo['marker_'.$marker_id]['longitude'] = $lat_long[1];
238: }
239: }
240:
241: $marker_output .= '
242: var markerOptions = {
243: map: '.$this->map_name;
244: if ($marker['position']!="") {
245: $marker_output .= ',
246: position: myLatlng';
247: }
248: if (!$marker['clickable']) {
249: $marker_output .= ',
250: clickable: false';
251: }
252: if ($marker['cursor']!="") {
253: $marker_output .= ',
254: cursor: "'.$marker['cursor'].'"';
255: }
256: if ($marker['draggable']) {
257: $marker_output .= ',
258: draggable: true';
259: }
260: if ($marker['flat']) {
261: $marker_output .= ',
262: flat: true';
263: }
264: if ($marker['icon']!="") {
265: $marker_output .= ',
266: icon: "'.$marker['icon'].'"';
267: }
268: if (!$marker['raiseondrag']) {
269: $marker_output .= ',
270: raiseOnDrag: false';
271: }
272: if ($marker['shadow']!="") {
273: $marker_output .= ',
274: shadow: "'.$marker['shadow'].'"';
275: }
276: if ($marker['title']!="") {
277: $marker_output .= ',
278: title: "'.$marker['title'].'"';
279: $this->markersInfo['marker_'.$marker_id]['title'] = $marker['title'];
280: }
281: if (!$marker['visible']) {
282: $marker_output .= ',
283: visible: false';
284: }
285: if ($marker['zIndex']!="" && is_numeric($marker['zIndex'])) {
286: $marker_output .= ',
287: zIndex: '.$marker['zIndex'];
288: }
289: if ($marker['animation']!="" && (strtoupper($marker['animation'])=="DROP" || strtoupper($marker['animation']=="BOUNCE"))) {
290: $marker_output .= ',
291: animation: google.maps.Animation.'.strtoupper($marker['animation']);
292: }
293: $marker_output .= '
294: };
295: marker_'.$marker_id.' = createMarker(markerOptions);
296: ';
297:
298: if ($marker['infowindow_content']!="") {
299:
300:
301: $marker['infowindow_content'] = str_replace('\"', '"', $marker['infowindow_content']);
302: $marker['infowindow_content'] = str_replace('"', '\"', $marker['infowindow_content']);
303: $marker_output .= '
304: marker_'.$marker_id.'.set("content", "'.$marker['infowindow_content'].'");
305:
306: google.maps.event.addListener(marker_'.$marker_id.', "click", function(event) {
307: iw.setContent(this.get("content"));
308: iw.open('.$this->map_name.', this);
309: ';
310: if ($marker['onclick']!="") { $marker_output .= $marker['onclick'].'
311: '; }
312: $marker_output .= '
313: });
314: ';
315:
316: $marker_output .= '
317: oms.addMarker(marker_'.$marker_id.');
318: ';
319:
320: }else{
321: if ($marker['onclick']!="") {
322: $marker_output .= '
323: google.maps.event.addListener(marker_'.$marker_id.', "click", function(event) {
324: '.$marker['onclick'].'
325: });
326: ';
327: }
328: }
329:
330: if ($marker['ondblclick']!="") {
331: $marker_output .= '
332: google.maps.event.addListener(marker_'.$marker_id.', "dblclick", function(event) {
333: '.$marker['ondblclick'].'
334: });
335: ';
336: }
337: if ($marker['onmousedown']!="") {
338: $marker_output .= '
339: google.maps.event.addListener(marker_'.$marker_id.', "mousedown", function(event) {
340: '.$marker['onmousedown'].'
341: });
342: ';
343: }
344: if ($marker['onmouseout']!="") {
345: $marker_output .= '
346: google.maps.event.addListener(marker_'.$marker_id.', "mouseout", function(event) {
347: '.$marker['onmouseout'].'
348: });
349: ';
350: }
351: if ($marker['onmouseover']!="") {
352: $marker_output .= '
353: google.maps.event.addListener(marker_'.$marker_id.', "mouseover", function(event) {
354: '.$marker['onmouseover'].'
355: });
356: ';
357: }
358: if ($marker['onmouseup']!="") {
359: $marker_output .= '
360: google.maps.event.addListener(marker_'.$marker_id.', "mouseup", function(event) {
361: '.$marker['onmouseup'].'
362: });
363: ';
364: }
365: if ($marker['onpositionchanged']!="") {
366: $marker_output .= '
367: google.maps.event.addListener(marker_'.$marker_id.', "position_changed", function(event) {
368: '.$marker['onpositionchanged'].'
369: });
370: ';
371: }
372: if ($marker['onrightclick']!="") {
373: $marker_output .= '
374: google.maps.event.addListener(marker_'.$marker_id.', "rightclick", function(event) {
375: '.$marker['onrightclick'].'
376: });
377: ';
378: }
379:
380: if ($marker['draggable']) {
381: if ($marker['ondrag']!="") {
382: $marker_output .= '
383: google.maps.event.addListener(marker_'.$marker_id.', "drag", function(event) {
384: '.$marker['ondrag'].'
385: });
386: ';
387: }
388: if ($marker['ondragend']!="") {
389: $marker_output .= '
390: google.maps.event.addListener(marker_'.$marker_id.', "dragend", function(event) {
391: '.$marker['ondragend'].'
392: });
393: ';
394: }
395: if ($marker['ondragstart']!="") {
396: $marker_output .= '
397: google.maps.event.addListener(marker_'.$marker_id.', "dragstart", function(event) {
398: '.$marker['ondragstart'].'
399: });
400: ';
401: }
402: }
403:
404: array_push($this->markers, $marker_output);
405:
406: }
407:
408: function add_polyline($params = array())
409: {
410:
411: $polyline = array();
412:
413: $polyline['points'] = array();
414: $polyline['clickable'] = TRUE;
415: $polyline['strokeColor'] = '#FF0000';
416: $polyline['strokeOpacity'] = '1.0';
417: $polyline['strokeWeight'] = '2';
418: $polyline['onclick'] = '';
419: $polyline['ondblclick'] = '';
420: $polyline['onmousedown'] = '';
421: $polyline['onmousemove'] = '';
422: $polyline['onmouseout'] = '';
423: $polyline['onmouseover'] = '';
424: $polyline['onmouseup'] = '';
425: $polyline['onrightclick'] = '';
426: $polyline['zIndex'] = '';
427:
428: $polyline_output = '';
429:
430: foreach ($params as $key => $value) {
431:
432: if (isset($polyline[$key])) {
433:
434: $polyline[$key] = $value;
435:
436: }
437:
438: }
439:
440: if (count($polyline['points'])) {
441:
442: $polyline_output .= '
443: var polyline_plan_'.count($this->polylines).' = [';
444: $i=0;
445: $lat_long_output = '';
446: foreach ($polyline['points'] as $point) {
447: if ($i>0) { $polyline_output .= ','; }
448: $lat_long_to_push = '';
449: if ($this->is_lat_long($point)) {
450: $lat_long_to_push = $point;
451: $polyline_output .= '
452: new google.maps.LatLng('.$point.')
453: ';
454: }else{
455: $lat_long = $this->get_lat_long_from_address($point);
456: $polyline_output .= '
457: new google.maps.LatLng('.$lat_long[0].', '.$lat_long[1].')';
458: $lat_long_to_push = $lat_long[0].', '.$lat_long[1];
459: }
460: $lat_long_output .= '
461: lat_longs.push(new google.maps.LatLng('.$lat_long_to_push.'));
462: ';
463: $i++;
464: }
465: $polyline_output .= '];';
466:
467: $polyline_output .= $lat_long_output;
468:
469: $polyline_output .= '
470: var polyline_'.count($this->polylines).' = new google.maps.Polyline({
471: path: polyline_plan_'.count($this->polylines).',
472: strokeColor: "'.$polyline['strokeColor'].'",
473: strokeOpacity: '.$polyline['strokeOpacity'].',
474: strokeWeight: '.$polyline['strokeWeight'];
475: if (!$polyline['clickable']) {
476: $polyline_output .= ',
477: clickable: false';
478: }
479: if ($polyline['zIndex']!="" && is_numeric($polyline['zIndex'])) {
480: $polyline_output .= ',
481: zIndex: '.$polyline['zIndex'];
482: }
483: $polyline_output .= '
484: });
485:
486: polyline_'.count($this->polylines).'.setMap('.$this->map_name.');
487:
488: ';
489:
490: if ($polyline['onclick']!="") {
491: $polyline_output .= '
492: google.maps.event.addListener(polyline_'.count($this->polylines).', "click", function() {
493: '.$polyline['onclick'].'
494: });
495: ';
496: }
497: if ($polyline['ondblclick']!="") {
498: $polyline_output .= '
499: google.maps.event.addListener(polyline_'.count($this->polylines).', "dblclick", function() {
500: '.$polyline['ondblclick'].'
501: });
502: ';
503: }
504: if ($polyline['onmousedown']!="") {
505: $polyline_output .= '
506: google.maps.event.addListener(polyline_'.count($this->polylines).', "mousedown", function() {
507: '.$polyline['onmousedown'].'
508: });
509: ';
510: }
511: if ($polyline['onmousemove']!="") {
512: $polyline_output .= '
513: google.maps.event.addListener(polyline_'.count($this->polylines).', "mousemove", function() {
514: '.$polyline['onmousemove'].'
515: });
516: ';
517: }
518: if ($polyline['onmouseout']!="") {
519: $polyline_output .= '
520: google.maps.event.addListener(polyline_'.count($this->polylines).', "mouseout", function() {
521: '.$polyline['onmouseout'].'
522: });
523: ';
524: }
525: if ($polyline['onmouseover']!="") {
526: $polyline_output .= '
527: google.maps.event.addListener(polyline_'.count($this->polylines).', "mouseover", function() {
528: '.$polyline['onmouseover'].'
529: });
530: ';
531: }
532: if ($polyline['onmouseup']!="") {
533: $polyline_output .= '
534: google.maps.event.addListener(polyline_'.count($this->polylines).', "mouseup", function() {
535: '.$polyline['onmouseup'].'
536: });
537: ';
538: }
539: if ($polyline['onrightclick']!="") {
540: $polyline_output .= '
541: google.maps.event.addListener(polyline_'.count($this->polylines).', "rightclick", function() {
542: '.$polyline['onrightclick'].'
543: });
544: ';
545: }
546:
547: array_push($this->polylines, $polyline_output);
548:
549: }
550:
551: }
552:
553: function add_polygon($params = array())
554: {
555:
556: $polygon = array();
557:
558: $polygon['points'] = array();
559: $polygon['clickable'] = TRUE;
560: $polygon['strokeColor'] = '#FF0000';
561: $polygon['strokeOpacity'] = '0.8';
562: $polygon['strokeWeight'] = '2';
563: $polygon['fillColor'] = '#FF0000';
564: $polygon['fillOpacity'] = '0.3';
565: $polygon['onclick'] = '';
566: $polygon['ondblclick'] = '';
567: $polygon['onmousedown'] = '';
568: $polygon['onmousemove'] = '';
569: $polygon['onmouseout'] = '';
570: $polygon['onmouseover'] = '';
571: $polygon['onmouseup'] = '';
572: $polygon['onrightclick'] = '';
573: $polygon['zIndex'] = '';
574:
575: $polygon_output = '';
576:
577: foreach ($params as $key => $value) {
578:
579: if (isset($polygon[$key])) {
580:
581: $polygon[$key] = $value;
582:
583: }
584:
585: }
586:
587: if (count($polygon['points'])) {
588:
589: $polygon_output .= '
590: var polygon_plan_'.count($this->polygons).' = [';
591: $i=0;
592: $lat_long_output = '';
593: foreach ($polygon['points'] as $point) {
594: if ($i>0) { $polygon_output .= ','; }
595: $lat_long_to_push = '';
596: if ($this->is_lat_long($point)) {
597: $lat_long_to_push = $point;
598: $polygon_output .= '
599: new google.maps.LatLng('.$point.')
600: ';
601: }else{
602: $lat_long = $this->get_lat_long_from_address($point);
603: $polygon_output .= '
604: new google.maps.LatLng('.$lat_long[0].', '.$lat_long[1].')';
605: $lat_long_to_push = $lat_long[0].', '.$lat_long[1];
606: }
607: $lat_long_output .= '
608: lat_longs.push(new google.maps.LatLng('.$lat_long_to_push.'));
609: ';
610: $i++;
611: }
612: $polygon_output .= '];';
613:
614: $polygon_output .= $lat_long_output;
615:
616: }
617:
618: $polygon_output .= '
619: var polygon_'.count($this->polygons).' = new google.maps.Polygon({
620: ';
621: if (count($polygon['points'])) {
622: $polygon_output .= 'path: polygon_plan_'.count($this->polygons).',
623: ';
624: }
625: $polygon_output .= '
626: strokeColor: "'.$polygon['strokeColor'].'",
627: strokeOpacity: '.$polygon['strokeOpacity'].',
628: strokeWeight: '.$polygon['strokeWeight'].',
629: fillColor: "'.$polygon['fillColor'].'",
630: fillOpacity: '.$polygon['fillOpacity'];
631: if (!$polygon['clickable']) {
632: $polygon_output .= ',
633: clickable: false';
634: }
635: if ($polygon['zIndex']!="" && is_numeric($polygon['zIndex'])) {
636: $polygon_output .= ',
637: zIndex: '.$polygon['zIndex'];
638: }
639: $polygon_output .= '
640: });
641:
642: polygon_'.count($this->polygons).'.setMap('.$this->map_name.');
643:
644: ';
645:
646: if ($polygon['onclick']!="") {
647: $polygon_output .= '
648: google.maps.event.addListener(polygon_'.count($this->polygons).', "click", function() {
649: '.$polygon['onclick'].'
650: });
651: ';
652: }
653: if ($polygon['ondblclick']!="") {
654: $polygon_output .= '
655: google.maps.event.addListener(polygon_'.count($this->polygons).', "dblclick", function() {
656: '.$polygon['ondblclick'].'
657: });
658: ';
659: }
660: if ($polygon['onmousedown']!="") {
661: $polygon_output .= '
662: google.maps.event.addListener(polygon_'.count($this->polygons).', "mousedown", function() {
663: '.$polygon['onmousedown'].'
664: });
665: ';
666: }
667: if ($polygon['onmousemove']!="") {
668: $polygon_output .= '
669: google.maps.event.addListener(polygon_'.count($this->polygons).', "mousemove", function() {
670: '.$polygon['onmousemove'].'
671: });
672: ';
673: }
674: if ($polygon['onmouseout']!="") {
675: $polygon_output .= '
676: google.maps.event.addListener(polygon_'.count($this->polygons).', "mouseout", function() {
677: '.$polygon['onmouseout'].'
678: });
679: ';
680: }
681: if ($polygon['onmouseover']!="") {
682: $polygon_output .= '
683: google.maps.event.addListener(polygon_'.count($this->polygons).', "mouseover", function() {
684: '.$polygon['onmouseover'].'
685: });
686: ';
687: }
688: if ($polygon['onmouseup']!="") {
689: $polygon_output .= '
690: google.maps.event.addListener(polygon_'.count($this->polygons).', "mouseup", function() {
691: '.$polygon['onmouseup'].'
692: });
693: ';
694: }
695: if ($polygon['onrightclick']!="") {
696: $polygon_output .= '
697: google.maps.event.addListener(polygon_'.count($this->polygons).', "rightclick", function() {
698: '.$polygon['onrightclick'].'
699: });
700: ';
701: }
702:
703: array_push($this->polygons, $polygon_output);
704:
705: }
706:
707: function add_circle($params = array())
708: {
709:
710: $circle = array();
711:
712: $circle['center'] = '';
713: $circle['clickable'] = TRUE;
714: $circle['radius'] = 0;
715: $circle['strokeColor'] = '0.8';
716: $circle['strokeOpacity'] = '0.8';
717: $circle['strokeWeight'] = '2';
718: $circle['fillColor'] = '#FF0000';
719: $circle['fillOpacity'] = '0.3';
720: $circle['onclick'] = '';
721: $circle['ondblclick'] = '';
722: $circle['onmousedown'] = '';
723: $circle['onmousemove'] = '';
724: $circle['onmouseout'] = '';
725: $circle['onmouseover'] = '';
726: $circle['onmouseup'] = '';
727: $circle['onrightclick'] = '';
728: $circle['zIndex'] = '';
729:
730: $circle_output = '';
731:
732: foreach ($params as $key => $value) {
733:
734: if (isset($circle[$key])) {
735:
736: $circle[$key] = $value;
737:
738: }
739:
740: }
741:
742: if ($circle['radius']>0 && $circle['center']!="") {
743:
744: $lat_long_to_push = '';
745: if ($this->is_lat_long($circle['center'])) {
746: $lat_long_to_push = $circle['center'];
747: $circle_output = '
748: var circleCenter = new google.maps.LatLng('.$circle['center'].')
749: ';
750: }else{
751: $lat_long = $this->get_lat_long_from_address($circle['center']);
752: $circle_output = '
753: var circleCenter = new google.maps.LatLng('.$lat_long[0].', '.$lat_long[1].')';
754: $lat_long_to_push = $lat_long[0].', '.$lat_long[1];
755: }
756: $circle_output .= '
757: lat_longs.push(new google.maps.LatLng('.$lat_long_to_push.'));
758: ';
759:
760: $circle_output .= '
761: var circleOptions = {
762: strokeColor: "'.$circle['strokeColor'].'",
763: strokeOpacity: '.$circle['strokeOpacity'].',
764: strokeWeight: '.$circle['strokeWeight'].',
765: fillColor: "'.$circle['fillColor'].'",
766: fillOpacity: '.$circle['fillOpacity'].',
767: map: '.$this->map_name.',
768: center: circleCenter,
769: radius: '.$circle['radius'];
770: if (!$circle['clickable']) {
771: $circle_output .= ',
772: clickable: false';
773: }
774: if ($circle['zIndex']!="" && is_numeric($circle['zIndex'])) {
775: $circle_output .= ',
776: zIndex: '.$circle['zIndex'];
777: }
778: $circle_output .= '
779: };
780: var circle_'.count($this->circles).' = new google.maps.Circle(circleOptions);
781: ';
782:
783: if ($circle['onclick']!="") {
784: $circle_output .= '
785: google.maps.event.addListener(circle_'.count($this->circles).', "click", function() {
786: '.$circle['onclick'].'
787: });
788: ';
789: }
790: if ($circle['ondblclick']!="") {
791: $circle_output .= '
792: google.maps.event.addListener(circle_'.count($this->circles).', "dblclick", function() {
793: '.$circle['ondblclick'].'
794: });
795: ';
796: }
797: if ($circle['onmousedown']!="") {
798: $circle_output .= '
799: google.maps.event.addListener(circle_'.count($this->circles).', "mousedown", function() {
800: '.$circle['onmousedown'].'
801: });
802: ';
803: }
804: if ($circle['onmousemove']!="") {
805: $circle_output .= '
806: google.maps.event.addListener(circle_'.count($this->circles).', "mousemove", function() {
807: '.$circle['onmousemove'].'
808: });
809: ';
810: }
811: if ($circle['onmouseout']!="") {
812: $circle_output .= '
813: google.maps.event.addListener(circle_'.count($this->circles).', "mouseout", function() {
814: '.$circle['onmouseout'].'
815: });
816: ';
817: }
818: if ($circle['onmouseover']!="") {
819: $circle_output .= '
820: google.maps.event.addListener(circle_'.count($this->circles).', "mouseover", function() {
821: '.$circle['onmouseover'].'
822: });
823: ';
824: }
825: if ($circle['onmouseup']!="") {
826: $circle_output .= '
827: google.maps.event.addListener(circle_'.count($this->circles).', "mouseup", function() {
828: '.$circle['onmouseup'].'
829: });
830: ';
831: }
832: if ($circle['onrightclick']!="") {
833: $circle_output .= '
834: google.maps.event.addListener(circle_'.count($this->circles).', "rightclick", function() {
835: '.$circle['onrightclick'].'
836: });
837: ';
838: }
839:
840: array_push($this->circles, $circle_output);
841:
842: }
843:
844: }
845:
846: function add_rectangle($params = array())
847: {
848:
849: $rectangle = array();
850:
851: $rectangle['positionSW'] = '';
852: $rectangle['positionNE'] = '';
853: $rectangle['clickable'] = TRUE;
854: $rectangle['strokeColor'] = '0.8';
855: $rectangle['strokeOpacity'] = '0.8';
856: $rectangle['strokeWeight'] = '2';
857: $rectangle['fillColor'] = '#FF0000';
858: $rectangle['fillOpacity'] = '0.3';
859: $rectangle['onclick'] = '';
860: $rectangle['ondblclick'] = '';
861: $rectangle['onmousedown'] = '';
862: $rectangle['onmousemove'] = '';
863: $rectangle['onmouseout'] = '';
864: $rectangle['onmouseover'] = '';
865: $rectangle['onmouseup'] = '';
866: $rectangle['onrightclick'] = '';
867: $rectangle['zIndex'] = '';
868:
869: $rectangle_output = '';
870:
871: foreach ($params as $key => $value) {
872:
873: if (isset($rectangle[$key])) {
874:
875: $rectangle[$key] = $value;
876:
877: }
878:
879: }
880:
881: if ($rectangle['positionSW']!="" && $rectangle['positionNE']!="") {
882:
883: $lat_long_to_push = '';
884: if ($this->is_lat_long($rectangle['positionSW'])) {
885: $lat_long_to_push = $rectangle['positionSW'];
886: $rectangle_output .= '
887: var positionSW = new google.maps.LatLng('.$rectangle['positionSW'].')
888: ';
889: }else{
890: $lat_long = $this->get_lat_long_from_address($rectangle['positionSW']);
891: $rectangle_output .= '
892: var positionSW = new google.maps.LatLng('.$lat_long[0].', '.$lat_long[1].')';
893: $lat_long_to_push = $lat_long[0].', '.$lat_long[1];
894: }
895: $rectangle_output .= '
896: lat_longs.push(new google.maps.LatLng('.$lat_long_to_push.'));
897: ';
898:
899: $lat_long_to_push = '';
900: if ($this->is_lat_long($rectangle['positionNE'])) {
901: $lat_long_to_push = $rectangle['positionNE'];
902: $rectangle_output .= '
903: var positionNE = new google.maps.LatLng('.$rectangle['positionNE'].')
904: ';
905: }else{
906: $lat_long = $this->get_lat_long_from_address($rectangle['positionNE']);
907: $rectangle_output .= '
908: var positionNE = new google.maps.LatLng('.$lat_long[0].', '.$lat_long[1].')';
909: $lat_long_to_push = $lat_long[0].', '.$lat_long[1];
910: }
911: $rectangle_output .= '
912: lat_longs.push(new google.maps.LatLng('.$lat_long_to_push.'));
913: ';
914:
915: $rectangle_output .= '
916: var rectangleOptions = {
917: strokeColor: "'.$rectangle['strokeColor'].'",
918: strokeOpacity: '.$rectangle['strokeOpacity'].',
919: strokeWeight: '.$rectangle['strokeWeight'].',
920: fillColor: "'.$rectangle['fillColor'].'",
921: fillOpacity: '.$rectangle['fillOpacity'].',
922: map: '.$this->map_name.',
923: bounds: new google.maps.LatLngBounds(positionSW, positionNE)';
924: if (!$rectangle['clickable']) {
925: $rectangle_output .= ',
926: clickable: false';
927: }
928: if ($rectangle['zIndex']!="" && is_numeric($rectangle['zIndex'])) {
929: $rectangle_output .= ',
930: zIndex: '.$rectangle['zIndex'];
931: }
932: $rectangle_output .= '
933: };';
934:
935: $rectangle_output .= '
936: var rectangle_'.count($this->rectangles).' = new google.maps.Rectangle(rectangleOptions);
937: ';
938:
939: if ($rectangle['onclick']!="") {
940: $rectangle_output .= '
941: google.maps.event.addListener(rectangle_'.count($this->rectangles).', "click", function() {
942: '.$rectangle['onclick'].'
943: });
944: ';
945: }
946: if ($rectangle['ondblclick']!="") {
947: $rectangle_output .= '
948: google.maps.event.addListener(rectangle_'.count($this->rectangles).', "dblclick", function() {
949: '.$rectangle['ondblclick'].'
950: });
951: ';
952: }
953: if ($rectangle['onmousedown']!="") {
954: $rectangle_output .= '
955: google.maps.event.addListener(rectangle_'.count($this->rectangles).', "mousedown", function() {
956: '.$rectangle['onmousedown'].'
957: });
958: ';
959: }
960: if ($rectangle['onmousemove']!="") {
961: $rectangle_output .= '
962: google.maps.event.addListener(rectangle_'.count($this->rectangles).', "mousemove", function() {
963: '.$rectangle['onmousemove'].'
964: });
965: ';
966: }
967: if ($rectangle['onmouseout']!="") {
968: $rectangle_output .= '
969: google.maps.event.addListener(rectangle_'.count($this->rectangles).', "mouseout", function() {
970: '.$rectangle['onmouseout'].'
971: });
972: ';
973: }
974: if ($rectangle['onmouseover']!="") {
975: $rectangle_output .= '
976: google.maps.event.addListener(rectangle_'.count($this->rectangles).', "mouseover", function() {
977: '.$rectangle['onmouseover'].'
978: });
979: ';
980: }
981: if ($rectangle['onmouseup']!="") {
982: $rectangle_output .= '
983: google.maps.event.addListener(rectangle_'.count($this->rectangles).', "mouseup", function() {
984: '.$rectangle['onmouseup'].'
985: });
986: ';
987: }
988: if ($rectangle['onrightclick']!="") {
989: $rectangle_output .= '
990: google.maps.event.addListener(rectangle_'.count($this->rectangles).', "rightclick", function() {
991: '.$rectangle['onrightclick'].'
992: });
993: ';
994: }
995:
996: array_push($this->rectangles, $rectangle_output);
997:
998: }
999:
1000: }
1001:
1002: function add_ground_overlay($params = array())
1003: {
1004:
1005: $overlay = array();
1006:
1007: $overlay['image'] = '';
1008: $overlay['positionSW'] = '';
1009: $overlay['positionNE'] = '';
1010: $overlay['clickable'] = TRUE;
1011: $overlay['onclick'] = '';
1012:
1013: $overlay_output = '';
1014:
1015: foreach ($params as $key => $value) {
1016:
1017: if (isset($overlay[$key])) {
1018:
1019: $overlay[$key] = $value;
1020:
1021: }
1022:
1023: }
1024:
1025: if ($overlay['image']!="" && $overlay['positionSW']!="" && $overlay['positionNE']!="") {
1026:
1027: $lat_long_to_push = '';
1028: if ($this->is_lat_long($overlay['positionSW'])) {
1029: $lat_long_to_push = $overlay['positionSW'];
1030: $overlay_output .= '
1031: var positionSW = new google.maps.LatLng('.$overlay['positionSW'].')
1032: ';
1033: }else{
1034: $lat_long = $this->get_lat_long_from_address($overlay['positionSW']);
1035: $overlay_output .= '
1036: var positionSW = new google.maps.LatLng('.$lat_long[0].', '.$lat_long[1].')';
1037: $lat_long_to_push = $lat_long[0].', '.$lat_long[1];
1038: }
1039: $overlay_output .= '
1040: lat_longs.push(new google.maps.LatLng('.$lat_long_to_push.'));
1041: ';
1042:
1043: $lat_long_to_push = '';
1044: if ($this->is_lat_long($overlay['positionNE'])) {
1045: $lat_long_to_push = $overlay['positionNE'];
1046: $overlay_output .= '
1047: var positionNE = new google.maps.LatLng('.$overlay['positionNE'].')
1048: ';
1049: }else{
1050: $lat_long = $this->get_lat_long_from_address($overlay['positionNE']);
1051: $overlay_output .= '
1052: var positionNE = new google.maps.LatLng('.$lat_long[0].', '.$lat_long[1].')';
1053: $lat_long_to_push = $lat_long[0].', '.$lat_long[1];
1054: }
1055: $overlay_output .= '
1056: lat_longs.push(new google.maps.LatLng('.$lat_long_to_push.'));
1057: ';
1058:
1059: $overlay_output .= '
1060: var overlay_'.count($this->overlays).' = new google.maps.GroundOverlay("'.$overlay['image'].'", new google.maps.LatLngBounds(positionSW, positionNE), { map: '.$this->map_name;
1061: if (!$overlay['clickable']) { $overlay_output .= ', clickable: false'; }
1062: $overlay_output .= '});
1063: ';
1064:
1065: if ($overlay['onclick']!="") {
1066: $overlay_output .= '
1067: google.maps.event.addListener(overlay_'.count($this->overlays).', "click", function() {
1068: '.$overlay['onclick'].'
1069: });
1070: ';
1071: }
1072:
1073: array_push($this->overlays, $overlay_output);
1074:
1075: }
1076:
1077: }
1078:
1079: function create_map()
1080: {
1081:
1082: $this->output_js = '';
1083: $this->output_js_contents = '';
1084: $this->output_html = '';
1085:
1086: if ($this->apiKey!="")
1087: {
1088: if ($this->https) { $apiLocation = 'https'; }else{ $apiLocation = 'http'; }
1089: $apiLocation .= '://maps.googleapis.com/maps/api/js?key='.$this->apiKey.'&';
1090: }
1091: else
1092: {
1093: if ($this->https) { $apiLocation = 'https://maps-api-ssl'; }else{ $apiLocation = 'http://maps'; }
1094: $apiLocation .= '.google.com/maps/api/js?';
1095: }
1096: $apiLocation .= 'sensor='.$this->sensor;
1097: if ($this->region!="" && strlen($this->region)==2) { $apiLocation .= '®ion='.strtoupper($this->region); }
1098: if ($this->language!="") { $apiLocation .= '&language='.$this->language; }
1099: $libraries = array();
1100: if ($this->adsense!="") { array_push($libraries, 'adsense'); }
1101: if ($this->places!="") { array_push($libraries, 'places'); }
1102: if ($this->panoramio) { array_push($libraries, 'panoramio'); }
1103: if ($this->drawing) { array_push($libraries, 'drawing'); }
1104: if (count($libraries)) { $apiLocation .= '&libraries='.implode(",", $libraries); }
1105: $this->output_js .= '
1106: <script type="text/javascript" src="'.$apiLocation.'"></script>';
1107: if ($this->center=="auto" || $this->directionsStart=="auto") { $this->output_js .= '
1108: <script type="text/javascript" src="http://code.google.com/apis/gears/gears_init.js"></script>
1109: '; }
1110: if ($this->cluster) { $this->output_js .= '
1111: <script type="text/javascript" src="' . WEBPATH . '/' . USER_PLUGIN_FOLDER . '/GoogleMap-plugins/markerclusterer.js"></script>
1112: '; }
1113: if ($this->jsfile=="") {
1114: $this->output_js .= '
1115: <script type="text/javascript">
1116: //<![CDATA[
1117: ';
1118: }
1119:
1120: $this->output_js_contents .= '
1121: var '.$this->map_name.'; // Global declaration of the map
1122:
1123: // hack zenphoto
1124: //var iw = new google.maps.InfoWindow(); // Global declaration of the infowindow
1125: var iw = new google.maps.InfoWindow({maxWidth:250}); // Global declaration of the infowindow
1126: var lat_longs = new Array();
1127: var markers = new Array();
1128: ';
1129: if ($this->cluster) {
1130: $this->output_js_contents .= 'var markerCluster;
1131: ';
1132: }
1133: if ($this->directions) {
1134: $rendererOptions = '';
1135: if ($this->directionsDraggable) {
1136: $this->output_js_contents .= '
1137: var rendererOptions = { draggable: true };
1138: ';
1139: $rendererOptions = 'rendererOptions';
1140: }
1141: $this->output_js_contents .= 'var directionsDisplay = new google.maps.DirectionsRenderer('.$rendererOptions.');
1142: var directionsService = new google.maps.DirectionsService();
1143: ';
1144: }
1145: if ($this->places) {
1146: $this->output_js_contents .= 'var placesService;
1147: ';
1148: if ($this->placesAutocompleteInputID != "")
1149: {
1150: $this->output_js_contents .= 'var placesAutocomplete;
1151: ';
1152: }
1153: }
1154: if ($this->adsense) {
1155: $this->output_js_contents .= 'var adUnit;
1156: ';
1157: }
1158: if ($this->drawing) {
1159: $this->output_js_contents .= 'var drawingManager;
1160: ';
1161: }
1162:
1163: $this->output_js_contents .= 'function initialize() {
1164:
1165: ';
1166:
1167: $styleOutput = '';
1168: if (count($this->styles)) {
1169: $styles = 0;
1170: foreach ($this->styles as $style) {
1171: $this->output_js_contents .= 'var styles_'.$styles.' = '.json_encode($style['definition']).';
1172: ';
1173:
1174: if ($this->stylesAsMapTypes) {
1175: $this->output_js_contents .= 'var styles_'.$styles.' = new google.maps.StyledMapType(styles_'.$styles.', {name:"'.$style['name'].'"});
1176: ';
1177: }else{
1178: $styleOutput .= $this->map_name.'.setOptions({styles: styles_'.$styles.'});
1179: ';
1180: break;
1181: }
1182:
1183: $styles++;
1184: }
1185: }
1186:
1187: if ($this->center!="auto") {
1188: if ($this->is_lat_long($this->center)) {
1189: $this->output_js_contents .= 'var myLatlng = new google.maps.LatLng('.$this->center.');';
1190: }else{
1191: $lat_long = $this->get_lat_long_from_address($this->center);
1192: $this->output_js_contents .= 'var myLatlng = new google.maps.LatLng('.$lat_long[0].', '.$lat_long[1].');';
1193: }
1194: }
1195:
1196: $this->output_js_contents .= '
1197: var myOptions = {
1198: ';
1199: if ($this->zoom=="auto") { $this->output_js_contents .= 'zoom: 13,'; }else{ $this->output_js_contents .= 'zoom: '.$this->zoom.','; }
1200: if ($this->center!="auto") { $this->output_js_contents .= '
1201: center: myLatlng,'; }
1202: if (strtolower($this->map_type)=="street") { $map_type = "ROADMAP"; }else{ $map_type = $this->map_type; }
1203: $this->output_js_contents .= '
1204: mapTypeId: google.maps.MapTypeId.'.$map_type;
1205: if ($this->backgroundColor) {
1206: $this->output_js_contents .= ',
1207: backgroundColor: \''.$this->backgroundColor.'\'';
1208: }
1209: if ($this->disableDefaultUI) {
1210: $this->output_js_contents .= ',
1211: disableDefaultUI: true';
1212: }
1213: if ($this->disableMapTypeControl) {
1214: $this->output_js_contents .= ',
1215: mapTypeControl: false';
1216: }
1217: if ($this->disableNavigationControl) {
1218: $this->output_js_contents .= ',
1219: navigationControl: false';
1220: }
1221: if ($this->disableScaleControl) {
1222: $this->output_js_contents .= ',
1223: scaleControl: false';
1224: }
1225: if ($this->disableStreetViewControl) {
1226: $this->output_js_contents .= ',
1227: streetViewControl: false';
1228: }
1229: if ($this->disableDoubleClickZoom) {
1230: $this->output_js_contents .= ',
1231: disableDoubleClickZoom: true';
1232: }
1233: if (!$this->draggable) {
1234: $this->output_js_contents .= ',
1235: draggable: false';
1236: }
1237: if ($this->draggableCursor!="") {
1238: $this->output_js_contents .= ',
1239: draggableCursor: "'.$this->draggableCursor.'"';
1240: }
1241: if ($this->draggingCursor!="") {
1242: $this->output_js_contents .= ',
1243: draggingCursor: "'.$this->draggingCursor.'"';
1244: }
1245: if (!$this->keyboardShortcuts) {
1246: $this->output_js_contents .= ',
1247: keyboardShortcuts: false';
1248: }
1249: $mapTypeControlOptions = array();
1250: $map_types = array();
1251: if ($this->mapTypeControlPosition!="") {
1252: array_push($mapTypeControlOptions, 'position: google.maps.ControlPosition.'.strtoupper($this->mapTypeControlPosition));
1253: }
1254: if ($this->mapTypeControlStyle!="" && (strtoupper($this->mapTypeControlStyle)=="DROPDOWN_MENU" || strtoupper($this->mapTypeControlStyle)=="HORIZONTAL_BAR")) {
1255: array_push($mapTypeControlOptions, 'style: google.maps.MapTypeControlStyle.'.strtoupper($this->mapTypeControlStyle));
1256: }
1257: if (count($this->map_types_available)) {
1258: foreach ($this->map_types_available as $map_type) { array_push($map_types, 'google.maps.MapTypeId.'.strtoupper($map_type)); }
1259: }
1260: if (count($this->styles) && $this->stylesAsMapTypes) {
1261: $styles = 0;
1262: foreach ($this->styles as $style) {
1263: array_push($map_types, '"style'.$styles.'"');
1264: $styleOutput .= '
1265: '.$this->map_name.'.mapTypes.set("style'.$styles.'", styles_'.$styles.');
1266: ';
1267: if ($this->stylesAsMapTypesDefault==$style['name']) {
1268: $styleOutput .= '
1269: '.$this->map_name.'.setMapTypeId("style'.$styles.'");
1270: ';
1271: }
1272: $styles++;
1273: }
1274: }
1275: if (count($map_types)) {
1276: array_push($mapTypeControlOptions, 'mapTypeIds: ['.implode(", ", $map_types).']');
1277: }
1278: if (count($mapTypeControlOptions)) {
1279: $this->output_js_contents .= ',
1280: mapTypeControlOptions: {'.implode(",", $mapTypeControlOptions).'}';
1281: }
1282: if ($this->minzoom!="") {
1283: $this->output_js_contents .= ',
1284: minZoom: '.$this->minzoom;
1285: }
1286: if ($this->maxzoom!="") {
1287: $this->output_js_contents .= ',
1288: maxZoom: '.$this->maxzoom;
1289: }
1290: if ($this->noClear) {
1291: $this->output_js_contents .= ',
1292: noClear: true';
1293: }
1294: if ($this->navigationControlPosition!="") {
1295: $this->output_js_contents .= ',
1296: navigationControlOptions: {position: google.maps.ControlPosition.'.strtoupper($this->navigationControlPosition).'}';
1297: }
1298: if ($this->scaleControlPosition!="") {
1299: $this->output_js_contents .= ',
1300: scaleControlOptions: {position: google.maps.ControlPosition.'.strtoupper($this->scaleControlPosition).'}';
1301: }
1302: if (!$this->scrollwheel) {
1303: $this->output_js_contents .= ',
1304: scrollwheel: false';
1305: }
1306: if ($this->streetViewControlPosition!="") {
1307: $this->output_js_contents .= ',
1308: streetViewControlOptions: {position: google.maps.ControlPosition.'.strtoupper($this->streetViewControlPosition).'}';
1309: }
1310: if ($this->tilt==45) {
1311: $this->output_js_contents .= ',
1312: tilt: '.$this->tilt;
1313: }
1314: $zoomControlOptions = array();
1315: if ($this->zoomControlPosition!="") { array_push($zoomControlOptions, 'position: google.maps.ControlPosition.'.strtoupper($this->zoomControlPosition)); }
1316: if ($this->zoomControlStyle!="" && (strtoupper($this->zoomControlStyle)=="SMALL" || strtoupper($this->zoomControlStyle)=="LARGE")) { array_push($zoomControlOptions, 'style: google.maps.ZoomControlStyle.'.strtoupper($this->zoomControlStyle)); }
1317: if (count($zoomControlOptions)) {
1318: $this->output_js_contents .= ',
1319: zoomControlOptions: {'.implode(",", $zoomControlOptions).'}';
1320: }
1321: $this->output_js_contents .= '}
1322: '.$this->map_name.' = new google.maps.Map(document.getElementById("'.$this->map_div_id.'"), myOptions);
1323: ';
1324:
1325: if ($styleOutput!="") {
1326: $this->output_js_contents .= $styleOutput.'
1327: ';
1328: }
1329:
1330:
1331: $this->output_js_contents .= '
1332: var oms = new OverlappingMarkerSpiderfier(map, {keepSpiderfied: true});
1333:
1334: oms.addListener("click", function(marker){
1335: iw.setContent(marker.get("content"));
1336: iw.open(map, marker);
1337: });
1338: oms.addListener("spiderfy", function(markers){
1339: iw.close();
1340: });
1341:
1342: ';
1343:
1344:
1345: if ($this->trafficOverlay) {
1346: $this->output_js_contents .= 'var trafficLayer = new google.maps.TrafficLayer();
1347: trafficLayer.setMap('.$this->map_name.');
1348: ';
1349: }
1350: if ($this->bicyclingOverlay) {
1351: $this->output_js_contents .= 'var bikeLayer = new google.maps.BicyclingLayer();
1352: bikeLayer.setMap('.$this->map_name.');
1353: ';
1354: }
1355:
1356: if ($this->kmlLayerURL!="") {
1357: $this->output_js_contents .= '
1358: var kmlLayerOptions = {
1359: map: '.$this->map_name;
1360: if ($this->kmlLayerPreserveViewport) {
1361: $this->output_js_contents .= ',
1362: preserveViewport: true';
1363: }
1364: $this->output_js_contents .= '
1365: }
1366: var kmlLayer = new google.maps.KmlLayer("'.$this->kmlLayerURL.'", kmlLayerOptions);
1367: ';
1368: }
1369:
1370: if ($this->panoramio) {
1371: $this->output_js_contents .= 'var panoramioLayer = new google.maps.panoramio.PanoramioLayer();
1372: ';
1373: if ($this->panoramioTag!="") { $this->output_js_contents .= 'panoramioLayer.setTag("'.$this->panoramioTag.'");
1374: '; }
1375: if ($this->panoramioUser!="") { $this->output_js_contents .= 'panoramioLayer.setUserId("'.$this->panoramioUser.'");
1376: '; }
1377: $this->output_js_contents .= '
1378: panoramioLayer.setMap('.$this->map_name.');
1379: ';
1380: }
1381:
1382: if (strtolower($this->map_type)=="street") {
1383: $this->output_js_contents .= '
1384: var streetViewOptions = {
1385: position: myLatlng';
1386: if (!$this->streetViewAddressControl) {
1387: $this->output_js_contents .= ',
1388: addressControl: false';
1389: }
1390: if ($this->streetViewAddressPosition!="") {
1391: $this->output_js_contents .= ',
1392: addressControlOptions: { position: google.maps.ControlPosition.'.$this->streetViewAddressPosition.' }';
1393: }
1394: if ($this->streetViewCloseButton) {
1395: $this->output_js_contents .= ',
1396: enableCloseButton: true';
1397: }
1398: if (!$this->streetViewLinksControl) {
1399: $this->output_js_contents .= ',
1400: linksControl: false';
1401: }
1402: if (!$this->streetViewPanControl) {
1403: $this->output_js_contents .= ',
1404: panControl: false';
1405: }
1406: if ($this->streetViewPanPosition!="") {
1407: $this->output_js_contents .= ',
1408: panControlOptions: { position: google.maps.ControlPosition.'.$this->streetViewPanPosition.' }';
1409: }
1410: if ($this->streetViewPovHeading!=0 || $this->streetViewPovPitch!=0 || $this->streetViewPovZoom!=0) {
1411: $this->output_js_contents .= ',
1412: pov: {
1413: heading: '.$this->streetViewPovHeading.',
1414: pitch: '.$this->streetViewPovPitch.',
1415: zoom: '.$this->streetViewPovZoom.'
1416: }';
1417: }
1418: if (!$this->streetViewZoomControl) {
1419: $this->output_js_contents .= ',
1420: zoomControl: false';
1421: }
1422: if ($this->streetViewZoomPosition!="" || $this->streetViewZoomStyle!="") {
1423: $this->output_js_contents .= ',
1424: zoomControlOptions: {';
1425: if ($this->streetViewZoomPosition!="") {
1426: $this->output_js_contents .= '
1427: position: google.maps.ControlPosition.'.$this->streetViewZoomPosition.',';
1428: }
1429: if ($this->streetViewZoomStyle!="") {
1430: $this->output_js_contents .= '
1431: style: google.maps.ZoomControlStyle.'.$this->streetViewZoomStyle.',';
1432: }
1433: $this->output_js_contents = trim($this->output_js_contents, ",");
1434: $this->output_js_contents .= '}';
1435: }
1436: $this->output_js_contents .= '
1437: };
1438: var streetView = new google.maps.StreetViewPanorama(document.getElementById("'.$this->map_div_id.'"), streetViewOptions);
1439: streetView.setVisible(true);
1440: ';
1441: }
1442:
1443: if ($this->center=="auto") {
1444: $this->output_js_contents .= '
1445: // Try W3C Geolocation (Preferred)
1446: if(navigator.geolocation) {
1447: navigator.geolocation.getCurrentPosition(function(position) {
1448: '.$this->map_name.'.setCenter(new google.maps.LatLng(position.coords.latitude,position.coords.longitude));
1449: }, function() { alert("Unable to get your current position. Please try again. Geolocation service failed."); });
1450: // Try Google Gears Geolocation
1451: } else if (google.gears) {
1452: var geo = google.gears.factory.create(\'beta.geolocation\');
1453: geo.getCurrentPosition(function(position) {
1454: '.$this->map_name.'.setCenter(new google.maps.LatLng(position.latitude,position.longitude));
1455: }, function() { alert("Unable to get your current position. Please try again. Geolocation service failed."); });
1456: // Browser doesn\'t support Geolocation
1457: }else{
1458: alert(\'Your browser does not support geolocation.\');
1459: }
1460: ';
1461: }
1462:
1463: if ($this->directions) {
1464: $this->output_js_contents .= 'directionsDisplay.setMap('.$this->map_name.');
1465: ';
1466: if ($this->directionsDivID!="") {
1467: $this->output_js_contents .= 'directionsDisplay.setPanel(document.getElementById("'.$this->directionsDivID.'"));
1468: ';
1469: }
1470: if ($this->directionsDraggable && $this->directionsChanged!="") {
1471: $this->output_js_contents .= 'google.maps.event.addListener(directionsDisplay, "directions_changed", function() {
1472: '.$this->directionsChanged.'
1473: });
1474: ';
1475: }
1476: }
1477:
1478: if ($this->drawing) {
1479:
1480: if ($this->drawingControlPosition=='') { $this->drawingControlPosition = 'TOP_CENTER'; }
1481:
1482: $this->output_js_contents .= 'drawingManager = new google.maps.drawing.DrawingManager({
1483: drawingMode: google.maps.drawing.OverlayType.'.strtoupper($this->drawingDefaultMode).',
1484: drawingControl: '.(!$this->drawingControl ? 'false' : 'true').',
1485: drawingControlOptions: {
1486: position: google.maps.ControlPosition.'.strtoupper($this->drawingControlPosition);
1487: $shapeOptions = '';
1488: if (count($this->drawingModes)) {
1489: $this->output_js_contents .= ',
1490: drawingModes: [';
1491: $i=0;
1492: foreach ($this->drawingModes as $drawingMode) {
1493: if ($i>0) { $this->output_js_contents .= ','; }
1494: $this->output_js_contents .= 'google.maps.drawing.OverlayType.'.strtoupper($drawingMode);
1495: if (strtoupper($drawingMode)!="MARKER") {
1496: $shapeOptions .= ',
1497: '.strtolower($drawingMode).'Options: {
1498: editable: true
1499: }';
1500: }
1501: $i++;
1502: }
1503: $this->output_js_contents .= ']';
1504: }
1505: $this->output_js_contents .= '
1506: }'.$shapeOptions.'
1507: });
1508: drawingManager.setMap('.$this->map_name.');
1509: ';
1510:
1511: $this->output_js_contents .= '
1512: google.maps.event.addListener(drawingManager, "overlaycomplete", function(event) {
1513: var newShape = event.overlay;
1514: newShape.type = event.type;
1515: ';
1516: if (count($this->drawingOnComplete)) {
1517: foreach ($this->drawingOnComplete as $shape=>$js) {
1518: $this->output_js_contents .= 'if (event.type==google.maps.drawing.OverlayType.'.strtoupper($shape).') {
1519: '.$js.'
1520: }
1521: ';
1522: }
1523: }
1524:
1525: if (count($this->drawingOnEdit)) {
1526:
1527: if (isset($this->drawingOnEdit['polygon'])) {
1528: $this->output_js_contents .= '
1529: if (newShape.type==google.maps.drawing.OverlayType.POLYGON) {
1530: var newShapePaths = newShape.getPaths();
1531: for (var i=0; i<newShapePaths.length; i++) {
1532: google.maps.event.addListener(newShapePaths.getAt(i), "set_at", function(event) {
1533: '.$this->drawingOnEdit['polygon'].'
1534: });
1535: google.maps.event.addListener(newShapePaths.getAt(i), "insert_at", function(event) {
1536: '.$this->drawingOnEdit['polygon'].'
1537: });
1538: google.maps.event.addListener(newShapePaths.getAt(i), "remove_at", function(event) {
1539: '.$this->drawingOnEdit['polygon'].'
1540: });
1541: }
1542: }';
1543: }
1544: if (isset($this->drawingOnEdit['polyline'])) {
1545: $this->output_js_contents .= '
1546: if (newShape.type==google.maps.drawing.OverlayType.POLYLINE) {
1547: var newShapePaths = newShape.getPaths();
1548: for (var i=0; i<newShapePaths.length; i++) {
1549: google.maps.event.addListener(newShapePaths.getAt(i), "set_at", function(event) {
1550: '.$this->drawingOnEdit['polyline'].'
1551: });
1552: google.maps.event.addListener(newShapePaths.getAt(i), "insert_at", function(event) {
1553: '.$this->drawingOnEdit['polyline'].'
1554: });
1555: google.maps.event.addListener(newShapePaths.getAt(i), "remove_at", function(event) {
1556: '.$this->drawingOnEdit['polyline'].'
1557: });
1558: }
1559: }';
1560: }
1561: if (isset($this->drawingOnEdit['rectangle'])) {
1562: $this->output_js_contents .= '
1563: if (newShape.type==google.maps.drawing.OverlayType.RECTANGLE) {
1564: google.maps.event.addListener(newShape, "bounds_changed", function(event) {
1565: '.$this->drawingOnEdit['rectangle'].'
1566: });
1567: }';
1568: }
1569: if (isset($this->drawingOnEdit['circle'])) {
1570: $this->output_js_contents .= '
1571: if (newShape.type==google.maps.drawing.OverlayType.CIRCLE) {
1572: google.maps.event.addListener(newShape, "radius_changed", function(event) {
1573: '.$this->drawingOnEdit['circle'].'
1574: });
1575: google.maps.event.addListener(newShape, "center_changed", function(event) {
1576: '.$this->drawingOnEdit['circle'].'
1577: });
1578: }';
1579: }
1580: }
1581:
1582: $this->output_js_contents .= '
1583: });';
1584:
1585: }
1586:
1587: if ($this->places) {
1588:
1589: $placesLocationSet = false;
1590:
1591: if ($this->placesLocationSW!="" && $this->placesLocationNE!="") {
1592:
1593: $placesLocationSet = true;
1594:
1595: if ($this->is_lat_long($this->placesLocationSW)) {
1596: $this->output_js_contents .= 'var placesLocationSW = new google.maps.LatLng('.$this->placesLocationSW.');
1597: ';
1598: }else{
1599: $lat_long = $this->get_lat_long_from_address($this->placesLocationSW);
1600: $this->output_js_contents .= 'var placesLocationSW = new google.maps.LatLng('.$lat_long[0].', '.$lat_long[1].');
1601: ';
1602: }
1603:
1604: if ($this->is_lat_long($this->placesLocationNE)) {
1605: $this->output_js_contents .= 'var placesLocationNE = new google.maps.LatLng('.$this->placesLocationNE.');
1606: ';
1607: }else{
1608: $lat_long = $this->get_lat_long_from_address($this->placesLocationNE);
1609: $this->output_js_contents .= 'var placesLocationNE = new google.maps.LatLng('.$lat_long[0].', '.$lat_long[1].');
1610: ';
1611: }
1612:
1613: }
1614:
1615: if (($placesLocationSet || $this->placesLocation!="") || count($this->placesTypes) || $this->placesName!="")
1616: {
1617: $this->output_js_contents .= 'var placesRequest = {
1618: ';
1619: if ($placesLocationSet) {
1620: $this->output_js_contents .= 'bounds: new google.maps.LatLngBounds(placesLocationSW, placesLocationNE)
1621: ';
1622: }else{
1623: if ($this->placesLocation!="") {
1624: if ($this->is_lat_long($this->placesLocation)) {
1625: $this->output_js_contents .= 'location: new google.maps.LatLng('.$this->placesLocation.')
1626: ';
1627: }else{
1628: $lat_long = $this->get_lat_long_from_address($this->placesLocation);
1629: $this->output_js_contents .= 'location: new google.maps.LatLng('.$lat_long[0].', '.$lat_long[1].')
1630: ';
1631: }
1632: $this->output_js_contents .= ',radius: '.$this->placesRadius.'
1633: ';
1634: }
1635: }
1636:
1637: if (count($this->placesTypes)) {
1638: $this->output_js_contents .= ',types: [\''.implode("','", $this->placesTypes).'\']
1639: ';
1640: }
1641: if ($this->placesName!="") {
1642: $this->output_js_contents .= ',name : \''.$this->placesName.'\'
1643: ';
1644: }
1645: $this->output_js_contents .= '};
1646:
1647: placesService = new google.maps.places.PlacesService('.$this->map_name.');
1648: placesService.search(placesRequest, placesCallback);
1649: ';
1650: }
1651:
1652: if ($this->placesAutocompleteInputID != "")
1653: {
1654: $this->output_js_contents .= 'var autocompleteOptions = {
1655: ';
1656: $autocompleteOptions = '';
1657: if ($this->placesAutocompleteBoundSW != "" && $this->placesAutocompleteBoundNE != "")
1658: {
1659: if ($this->is_lat_long($this->placesAutocompleteBoundSW)) {
1660: $autocompleteOptionsSW = 'new google.maps.LatLng('.$this->placesAutocompleteBoundSW.')
1661: ';
1662: }else{
1663: $lat_long = $this->get_lat_long_from_address($this->placesAutocompleteBoundSW);
1664: $autocompleteOptionsSW = 'new google.maps.LatLng('.$lat_long[0].', '.$lat_long[1].')
1665: ';
1666: }
1667:
1668: if ($this->is_lat_long($this->placesAutocompleteBoundNE)) {
1669: $autocompleteOptionsNE = 'new google.maps.LatLng('.$this->placesAutocompleteBoundNE.')
1670: ';
1671: }else{
1672: $lat_long = $this->get_lat_long_from_address($this->placesAutocompleteBoundNE);
1673: $autocompleteOptionsNE = 'new google.maps.LatLng('.$lat_long[0].', '.$lat_long[1].')
1674: ';
1675: }
1676: $autocompleteOptions .= 'bounds: new google.maps.LatLngBounds('.$autocompleteOptionsSW.', '.$autocompleteOptionsNE.')';
1677: }
1678: if (count($this->placesAutocompleteTypes))
1679: {
1680: if ($autocompleteOptions != "")
1681: {
1682: $autocompleteOptions .= ',
1683: ';
1684: }
1685: $autocompleteOptions .= 'types: [\''.implode("','", $this->placesAutocompleteTypes).'\']';
1686: }
1687: $this->output_js_contents .= $autocompleteOptions;
1688: $this->output_js_contents .= '}';
1689:
1690: $this->output_js_contents .= '
1691: var autocompleteInput = document.getElementById(\''.$this->placesAutocompleteInputID.'\');
1692:
1693: placesAutocomplete = new google.maps.places.Autocomplete(autocompleteInput, autocompleteOptions);
1694: ';
1695:
1696: if ($this->placesAutocompleteBoundsMap)
1697: {
1698: $this->output_js_contents .= 'placesAutocomplete.bindTo(\'bounds\', map);
1699: ';
1700: }
1701:
1702: if ($this->placesAutocompleteOnChange != "")
1703: {
1704: $this->output_js_contents .= 'google.maps.event.addListener(placesAutocomplete, \'place_changed\', function() {
1705: '.$this->placesAutocompleteOnChange.'
1706: });
1707: ';
1708: }
1709: }
1710:
1711: }
1712:
1713: if ($this->onboundschanged!="") {
1714: $this->output_js_contents .= 'google.maps.event.addListener(map, "bounds_changed", function(event) {
1715: '.$this->onboundschanged.'
1716: });
1717: ';
1718: }
1719: if ($this->oncenterchanged!="") {
1720: $this->output_js_contents .= 'google.maps.event.addListener(map, "center_changed", function(event) {
1721: '.$this->oncenterchanged.'
1722: });
1723: ';
1724: }
1725: if ($this->onclick!="") {
1726: $this->output_js_contents .= 'google.maps.event.addListener(map, "click", function(event) {
1727: '.$this->onclick.'
1728: });
1729: ';
1730: }
1731: if ($this->ondblclick!="") {
1732: $this->output_js_contents .= 'google.maps.event.addListener(map, "dblclick", function(event) {
1733: '.$this->ondblclick.'
1734: });
1735: ';
1736: }
1737: if ($this->ondrag!="") {
1738: $this->output_js_contents .= 'google.maps.event.addListener(map, "drag", function(event) {
1739: '.$this->ondrag.'
1740: });
1741: ';
1742: }
1743: if ($this->ondragend!="") {
1744: $this->output_js_contents .= 'google.maps.event.addListener(map, "dragend", function(event) {
1745: '.$this->ondragend.'
1746: });
1747: ';
1748: }
1749: if ($this->ondragstart!="") {
1750: $this->output_js_contents .= 'google.maps.event.addListener(map, "dragstart", function(event) {
1751: '.$this->ondragstart.'
1752: });
1753: ';
1754: }
1755: if ($this->onidle!="") {
1756: $this->output_js_contents .= 'google.maps.event.addListener(map, "idle", function(event) {
1757: '.$this->onidle.'
1758: });
1759: ';
1760: }
1761: if ($this->onmousemove!="") {
1762: $this->output_js_contents .= 'google.maps.event.addListener(map, "mousemove", function(event) {
1763: '.$this->onmousemove.'
1764: });
1765: ';
1766: }
1767: if ($this->onmouseout!="") {
1768: $this->output_js_contents .= 'google.maps.event.addListener(map, "mouseout", function(event) {
1769: '.$this->onmouseout.'
1770: });
1771: ';
1772: }
1773: if ($this->onmouseover!="") {
1774: $this->output_js_contents .= 'google.maps.event.addListener(map, "mouseover", function(event) {
1775: '.$this->onmouseover.'
1776: });
1777: ';
1778: }
1779: if ($this->onresize!="") {
1780: $this->output_js_contents .= 'google.maps.event.addListener(map, "resize", function(event) {
1781: '.$this->onresize.'
1782: });
1783: ';
1784: }
1785: if ($this->onrightclick!="") {
1786: $this->output_js_contents .= 'google.maps.event.addListener(map, "rightclick", function(event) {
1787: '.$this->onrightclick.'
1788: });
1789: ';
1790: }
1791: if ($this->ontilesloaded!="") {
1792: $this->output_js_contents .= 'google.maps.event.addListener(map, "tilesloaded", function(event) {
1793: '.$this->ontilesloaded.'
1794: });
1795: ';
1796: }
1797: if ($this->onzoomchanged!="") {
1798: $this->output_js_contents .= 'google.maps.event.addListener(map, "zoom_changed", function(event) {
1799: '.$this->onzoomchanged.'
1800: });
1801: ';
1802: }
1803:
1804:
1805: if (count($this->markers)) {
1806: foreach ($this->markers as $marker) {
1807: $this->output_js_contents .= $marker;
1808: }
1809: }
1810:
1811:
1812: if ($this->cluster) {
1813: $this->output_js_contents .= '
1814: var clusterOptions = {
1815: gridSize: '.$this->clusterGridSize;
1816: if ($this->clusterMaxZoom!="") { $this->output_js_contents .= ',
1817: maxZoom: '.$this->clusterMaxZoom; }
1818: if (!$this->clusterZoomOnClick) { $this->output_js_contents .= ',
1819: zoomOnClick: false'; }
1820: if ($this->clusterAverageCenter) { $this->output_js_contents .= ',
1821: averageCenter: true'; }
1822:
1823:
1824: $this->output_js_contents .= ',
1825: imagePath: "' . WEBPATH . '/' . ZENFOLDER . '/' . PLUGIN_FOLDER . '/GoogleMap/markerClustererPlus/images/m"';
1826:
1827: $this->output_js_contents .= ',
1828: minimumClusterSize: '.$this->clusterMinimumClusterSize.'
1829: };
1830: markerCluster = new MarkerClusterer('.$this->map_name.', markers, clusterOptions);
1831: ';
1832: }
1833:
1834:
1835: if (count($this->polylines)) {
1836: foreach ($this->polylines as $polyline) {
1837: $this->output_js_contents .= $polyline;
1838: }
1839: }
1840:
1841:
1842:
1843: if (count($this->polygons)) {
1844: foreach ($this->polygons as $polygon) {
1845: $this->output_js_contents .= $polygon;
1846: }
1847: }
1848:
1849:
1850:
1851: if (count($this->circles)) {
1852: foreach ($this->circles as $circle) {
1853: $this->output_js_contents .= $circle;
1854: }
1855: }
1856:
1857:
1858:
1859: if (count($this->rectangles)) {
1860: foreach ($this->rectangles as $rectangle) {
1861: $this->output_js_contents .= $rectangle;
1862: }
1863: }
1864:
1865:
1866:
1867: if (count($this->overlays)) {
1868: foreach ($this->overlays as $overlay) {
1869: $this->output_js_contents .= $overlay;
1870: }
1871: }
1872:
1873:
1874: if ($this->zoom=="auto") {
1875:
1876: $this->output_js_contents .= '
1877: fitMapToBounds();
1878: ';
1879:
1880: }
1881:
1882: if ($this->adsense) {
1883: $this->output_js_contents .= '
1884: var adUnitDiv = document.createElement("div");
1885:
1886: // Note: replace the publisher ID noted here with your own
1887: // publisher ID.
1888: var adUnitOptions = {
1889: format: google.maps.adsense.AdFormat.'.$this->adsenseFormat.',
1890: position: google.maps.ControlPosition.'.$this->adsensePosition.',
1891: publisherId: "'.$this->adsensePublisherID.'",
1892: ';
1893: if ($this->adsenseChannelNumber!="") { $this->output_js_contents .= 'channelNumber: "'.$this->adsenseChannelNumber.'",
1894: '; }
1895: $this->output_js_contents .= 'map: map,
1896: visible: true
1897: };
1898: adUnit = new google.maps.adsense.AdUnit(adUnitDiv, adUnitOptions);
1899: ';
1900: }
1901:
1902: if ($this->directions && $this->directionsStart!="" && $this->directionsEnd!="") {
1903: if ($this->directionsStart=="auto") {
1904: $this->output_js_contents .= '
1905: // Try W3C Geolocation (Preferred)
1906: if(navigator.geolocation) {
1907: navigator.geolocation.getCurrentPosition(function(position) {
1908: start = position.coords.latitude+","+position.coords.longitude;
1909: calcRoute(start, \''.$this->directionsEnd.'\');
1910: }, function() { alert("Unable to get your current position. Please try again. Geolocation service failed."); });
1911: // Try Google Gears Geolocation
1912: } else if (google.gears) {
1913: var geo = google.gears.factory.create(\'beta.geolocation\');
1914: geo.getCurrentPosition(function(position) {
1915: start = position.latitude+","+position.longitude;
1916: calcRoute(start, \''.$this->directionsEnd.'\');
1917: }, function() { alert("Unable to get your current position. Please try again. Geolocation service failed."); });
1918: // Browser doesn\'t support Geolocation
1919: }else{
1920: alert(\'Your browser does not support geolocation.\');
1921: }
1922: ';
1923: }else{
1924: $this->output_js_contents .= '
1925: calcRoute(\''.$this->directionsStart.'\', \''.$this->directionsEnd.'\');
1926: ';
1927: }
1928: }
1929:
1930: if ($this->onload!="") {
1931: $this->output_js_contents .= '
1932: '.$this->onload;
1933: }
1934:
1935: $this->output_js_contents .= '
1936:
1937: }
1938:
1939: ';
1940:
1941:
1942: $this->output_js_contents .= '
1943: function createMarker(markerOptions) {
1944: var marker = new google.maps.Marker(markerOptions);
1945: markers.push(marker);
1946: lat_longs.push(marker.getPosition());
1947: return marker;
1948: }
1949: ';
1950:
1951:
1952: if ($this->directions) {
1953:
1954: $this->output_js_contents .= 'function calcRoute(start, end) {
1955:
1956: var request = {
1957: origin:start,
1958: destination:end,
1959: travelMode: google.maps.TravelMode.'.$this->directionsMode.'
1960: ';
1961: if ($this->region!="" && strlen($this->region)==2) {
1962: $this->output_js_contents .= ',region: '.strtoupper($this->region).'
1963: ';
1964: }
1965: if (trim($this->directionsUnits)!="" && (strtolower(trim($this->directionsUnits)) == "metric" || strtolower(trim($this->directionsUnits)) == "imperial")) {
1966: $this->output_js_contents .= ',unitSystem: google.maps.UnitSystem.'.strtoupper(trim($this->directionsUnits)).'
1967: ';
1968: }
1969: if ($this->directionsAvoidTolls) {
1970: $this->output_js_contents .= ',avoidTolls: true
1971: ';
1972: }
1973: if ($this->directionsAvoidHighways) {
1974: $this->output_js_contents .= ',avoidHighways: true
1975: ';
1976: }
1977:
1978: $this->output_js_contents .= '
1979: };
1980: directionsService.route(request, function(response, status) {
1981: if (status == google.maps.DirectionsStatus.OK) {
1982: directionsDisplay.setDirections(response);
1983: }else{
1984: switch (status) {
1985: case "NOT_FOUND": { alert("Either the start location or destination were not recognised"); break }
1986: case "ZERO_RESULTS": { alert("No route could be found between the start location and destination"); break }
1987: case "MAX_WAYPOINTS_EXCEEDED": { alert("Maximum waypoints exceeded. Maximum of 8 allowed"); break }
1988: case "INVALID_REQUEST": { alert("Invalid request made for obtaining directions"); break }
1989: case "OVER_QUERY_LIMIT": { alert("This webpage has sent too many requests recently. Please try again later"); break }
1990: case "REQUEST_DENIED": { alert("This webpage is not allowed to request directions"); break }
1991: case "UNKNOWN_ERROR": { alert("Unknown error with the server. Please try again later"); break }
1992: }
1993: }
1994: });
1995: }
1996: ';
1997:
1998: }
1999:
2000: if ($this->places) {
2001: $this->output_js_contents .= 'function placesCallback(results, status) {
2002: if (status == google.maps.places.PlacesServiceStatus.OK) {
2003: for (var i = 0; i < results.length; i++) {
2004:
2005: var place = results[i];
2006:
2007: var placeLoc = place.geometry.location;
2008: var placePosition = new google.maps.LatLng(placeLoc.lat(), placeLoc.lng());
2009: var markerOptions = {
2010: map: '.$this->map_name.',
2011: position: placePosition
2012: };
2013: var marker = createMarker(markerOptions);
2014: marker.set("content", place.name);
2015: google.maps.event.addListener(marker, "click", function() {
2016: iw.setContent(this.get("content"));
2017: iw.open('.$this->map_name.', this);
2018: });
2019:
2020: lat_longs.push(placePosition);
2021:
2022: }
2023: ';
2024: if ($this->zoom=="auto") { $this->output_js_contents .= 'fitMapToBounds();'; }
2025: $this->output_js_contents .= '
2026: }
2027: }
2028: ';
2029: }
2030:
2031: if ($this->zoom=="auto") {
2032: $this->output_js_contents .= '
2033: function fitMapToBounds() {
2034: var bounds = new google.maps.LatLngBounds();
2035: if (lat_longs.length>0) {
2036: for (var i=0; i<lat_longs.length; i++) {
2037: bounds.extend(lat_longs[i]);
2038: }
2039: '.$this->map_name.'.fitBounds(bounds);
2040: }
2041: }
2042: ';
2043: }
2044:
2045: if ($this->loadAsynchronously) {
2046: $this->output_js_contents .= '
2047: function loadScript() {
2048: var script = document.createElement("script");
2049: script.type = "text/javascript";
2050: script.src = "'.$apiLocation.'&callback=initialize";
2051: document.body.appendChild(script);
2052: }
2053: window.onload = loadScript;
2054: ';
2055: }else{
2056: $this->output_js_contents .= '
2057: window.onload = initialize;
2058:
2059: // hack zenphoto - recenter map after resize
2060: google.maps.event.addDomListener(window, "resize", function() {
2061: var center = map.getCenter();
2062: google.maps.event.trigger(map, "resize");
2063: map.setCenter(center);
2064: });
2065:
2066: ';
2067: }
2068:
2069:
2070: if ($this->minifyJS) {
2071: $CI = get_instance();
2072: $CI->load->library('jsmin');
2073: $this->output_js_contents = $CI->jsmin->min($this->output_js_contents);
2074: }
2075: if ($this->jsfile=="") {
2076: $this->output_js .= $this->output_js_contents;
2077: }else{
2078: if (!$handle = fopen($this->jsfile, "w")) {
2079: $this->output_js .= $this->output_js_contents;
2080: }else{
2081: if (!fwrite($handle, $this->output_js_contents)) {
2082: $this->output_js .= $this->output_js_contents;
2083: }else{
2084: $this->output_js .= '
2085: <script src="'.$this->jsfile.'" type="text/javascript"></script>';
2086: }
2087: }
2088: }
2089:
2090: if ($this->jsfile=="") {
2091: $this->output_js .= '
2092: //]]>
2093: </script>';
2094: }
2095:
2096:
2097:
2098:
2099: if (is_numeric($this->map_width)) {
2100: $this->map_width = $this->map_width.'px';
2101: }
2102: if (is_numeric($this->map_height)) {
2103: $this->map_height = $this->map_height.'px';
2104: }
2105:
2106:
2107: $this->output_html .= '<div id="'.$this->map_div_id.'"></div>';
2108:
2109: return array('js'=>$this->output_js, 'html'=>$this->output_html, 'markers'=>$this->markersInfo);
2110:
2111: }
2112:
2113: function is_lat_long($input)
2114: {
2115:
2116: $input = str_replace(", ", ",", trim($input));
2117: $input = explode(",", $input);
2118: if (count($input)==2) {
2119:
2120: if (is_numeric($input[0]) && is_numeric($input[1])) {
2121: return true;
2122: }else{
2123: return false;
2124: }
2125:
2126: }else{
2127: return false;
2128: }
2129:
2130: }
2131:
2132: function get_lat_long_from_address($address, $attempts = 0)
2133: {
2134:
2135: $lat = 0;
2136: $lng = 0;
2137:
2138: $error = '';
2139:
2140: if ($this->geocodeCaching) {
2141:
2142: $CI = get_instance();
2143: $CI->load->database();
2144: $CI->db->select("latitude,longitude");
2145: $CI->db->from("geocoding");
2146: $CI->db->where("address", trim(strtolower($address)));
2147: $query = $CI->db->get();
2148:
2149: if ($query->num_rows()>0) {
2150: $row = $query->row();
2151: return array($row->latitude, $row->longitude);
2152: }
2153:
2154: }
2155: if ($this->https) { $data_location = 'https://'; }else{ $data_location = 'http://'; }
2156: $data_location .= "maps.google.com/maps/api/geocode/json?address=".urlencode(utf8_encode($address))."&sensor=".$this->sensor;
2157: if ($this->region!="" && strlen($this->region)==2) { $data_location .= "®ion=".$this->region; }
2158: $data = file_get_contents($data_location);
2159:
2160: $data = json_decode($data);
2161:
2162: if ($data->status=="OK")
2163: {
2164: $lat = $data->results[0]->geometry->location->lat;
2165: $lng = $data->results[0]->geometry->location->lng;
2166:
2167: if ($this->geocodeCaching) {
2168: $data = array(
2169: "address"=>trim(strtolower($address)),
2170: "latitude"=>$lat,
2171: "longitude"=>$lng
2172: );
2173: $CI->db->insert("geocoding", $data);
2174: }
2175: }
2176: else
2177: {
2178: if ($data->status == "OVER_QUERY_LIMIT")
2179: {
2180: $error = $data->status;
2181: if ($attempts < 2)
2182: {
2183: sleep(1);
2184: ++$attempts;
2185: list($lat, $lng, $error) = $this->get_lat_long_from_address($address, $attempts);
2186: }
2187: }
2188: }
2189:
2190: return array($lat, $lng, $error);
2191:
2192: }
2193:
2194: }
2195:
2196: ?>