[ Index ] |
MailPress 7.2 |
[ Index ] [ Classes ] [ Functions ] [ Variables ] [ Constants ] [ Statistics ] |
[Summary view] [Print] [Text view]
1 function mp_map(data) 2 { 3 this.map = null; 4 5 this.data = data; 6 this.settings = data.settings; 7 this.prefix = this.settings.prefix; 8 9 this.center_lat = jQuery('#' + this.prefix + '_center_lat'); 10 this.center_lng = jQuery('#' + this.prefix + '_center_lng'); 11 12 this.zoomlevel = jQuery('#' + this.prefix + '_zoomlevel'); 13 this.maptype = jQuery('#' + this.prefix + '_maptype'); 14 15 this.container = document.getElementById(this.prefix + '_map'); 16 17 this.count = parseInt(this.settings.count); 18 this.max = 10; 19 20 this.infowindow = false; 21 22 this.init = function() { 23 24 this.center = this.getLatLng(this.setLoLa(this.settings.center_lng, this.settings.center_lat)); 25 26 var myOptions = { 27 center: this.center, 28 zoom: parseInt(this.zoomlevel.val()), 29 mapTypeId: this.get_maptype(this.maptype.val()), 30 31 gestureHandling: 'greedy', 32 draggable: true, 33 34 disableDefaultUI: true, 35 mapTypeControl: false, 36 panControl: false, 37 zoomControlOptions: {style:'SMALL'} 38 }; 39 40 this.map = new google.maps.Map(this.container, myOptions); 41 42 if ( this.count ) 43 { 44 var markers = new Array(); 45 for (var i in this.data.markers) markers.push(this.setMarker(this.data.markers[i])); 46 if ( this.count >= this.max ) this.setCluster( markers ); 47 } 48 49 this.setEvents(); 50 this.setControls(); 51 this.scheduler(); 52 }; 53 54 this.sanitize = function(x) { 55 x = parseFloat(x); 56 return x.toFixed(8); 57 }; 58 59 this.setLoLa = function(lng, lat) { 60 return { lo: this.sanitize(lng), la: this.sanitize(lat) }; 61 }; 62 63 this.getLoLa = function(LatLng) { 64 return { lo: this.sanitize(LatLng.lng()), la: this.sanitize(LatLng.lat()) }; 65 }; 66 67 this.getLatLng = function(LoLa) { 68 return new google.maps.LatLng(LoLa.la, LoLa.lo); 69 }; 70 71 this.setMarker = function(data) { 72 73 var mkOptions = { 74 position: this.getLatLng(this.setLoLa(data['lng'], data['lat'])), 75 map: this.map, 76 title: data['ip'] 77 }; 78 79 if(typeof(data['icon']) != "undefined") 80 mkOptions['icon'] = new google.maps.MarkerImage(data['icon']); 81 82 var marker = new google.maps.Marker(mkOptions); 83 84 if(typeof(data['info']) != "undefined") 85 { 86 google.maps.event.addListener(marker, 'click', function() { 87 if (_this.infowindow) _this.infowindow.close(); 88 _this.infowindow = new google.maps.InfoWindow({content:data['info']}); 89 _this.infowindow.open(_this.map, marker); 90 }); 91 } 92 return marker; 93 }; 94 95 this.setCluster = function(markers) { 96 new MarkerClusterer(this.map, markers, {imagePath: mp_mapL10n.url+'m'}); 97 }; 98 99 this.get_maptype = function(maptype) { 100 var s = v = null; 101 switch(maptype) 102 { 103 case 'SATELLITE': s = google.maps.MapTypeId.SATELLITE; break; 104 case 'HYBRID' : s = google.maps.MapTypeId.HYBRID; break; 105 case 'TERRAIN' : s = google.maps.MapTypeId.TERRAIN; break; 106 default : s = google.maps.MapTypeId.ROADMAP; break; 107 } 108 return s; 109 }; 110 111 this.setEvents = function() { 112 // map 113 google.maps.event.addListener(_this.map, 'click', function() { 114 if (_this.infowindow) _this.infowindow.close(); 115 }); 116 117 google.maps.event.addListener(_this.map, 'dragend', function() { 118 var LoLa = _this.getLoLa(_this.map.getCenter()); 119 _this.center_lat.val(LoLa.la); 120 _this.center_lng.val(LoLa.lo); 121 }); 122 123 google.maps.event.addListener(this.map, 'zoom_changed', function() { 124 _this.zoomlevel.val(parseInt(_this.map.getZoom())); 125 }); 126 }; 127 128 this.setControls = function() { 129 130 var container = document.createElement('div'); 131 container.setAttribute('class', 'google-ctrl google-ctrl-group'); 132 133 var button = document.createElement('button'); 134 button.setAttribute('type', 'button'); 135 button.setAttribute('alt', mp_mapL10n.changemap); 136 button.setAttribute('title', mp_mapL10n.changemap); 137 button.setAttribute('class', 'google-ctrl-icon map_control'); 138 container.appendChild(button); 139 140 google.maps.event.addDomListener(button, 'click', function() 141 { 142 switch (_this.maptype.val()) 143 { 144 case 'ROADMAP' : _this.maptype.val('SATELLITE'); break; 145 case 'SATELLITE' : _this.maptype.val('HYBRID'); break; 146 case 'HYBRID' : _this.maptype.val('TERRAIN'); break; 147 default: _this.maptype.val('ROADMAP'); break; 148 } 149 var s = _this.get_maptype(_this.maptype.val()); 150 _this.map.setMapTypeId(s); 151 return false; 152 }); 153 154 button = document.createElement('button'); 155 button.setAttribute('type', 'button'); 156 button.setAttribute('alt', mp_mapL10n.center); 157 button.setAttribute('title', mp_mapL10n.center); 158 button.setAttribute('class', 'google-ctrl-icon map_center'); 159 container.appendChild(button); 160 161 google.maps.event.addDomListener(button, 'click', function() { 162 var LoLa = _this.getLoLa(_this.center); 163 _this.map.setCenter(_this.center); 164 _this.center_lat.val(LoLa.la); 165 _this.center_lng.val(LoLa.lo); 166 return false; 167 }); 168 169 this.map.controls[google.maps.ControlPosition.TOP_RIGHT].push(container); 170 }; 171 172 this.scheduler = function() { 173 jQuery.schedule({ id: _this.prefix + '_schedule', 174 time: 60000, 175 func: function() { _this.update_settings(); }, 176 repeat: true, 177 protect: true 178 }); 179 }; 180 181 this.update_settings = function() { 182 var data = {}; 183 data['action'] = 'mp_ajax'; 184 data['mp_action'] = 'map_settings'; 185 data['id'] = mp_mapL10n.id; 186 data['type'] = mp_mapL10n.type; 187 data['prefix'] = this.prefix; 188 data['settings[center_lat]'] = this.center_lat.val(); 189 data['settings[center_lng]'] = this.center_lng.val(); 190 data['settings[zoomlevel]'] = this.zoomlevel.val(); 191 data['settings[maptype]'] = this.maptype.val(); 192 193 jQuery.ajax({ 194 data: data, 195 beforeSend: null, 196 type: "POST", 197 url: ajaxurl, 198 success: null 199 }); 200 }; 201 202 var _this = this; 203 204 this.init(); 205 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Tue May 19 15:55:14 2020 | Cross-referenced by PHPXref 0.7.1 |