1function umsBaseMap(elementId, mapData, engine, additionalParams) { 2 mapData = mapData ? mapData : {}; 3 additionalParams = additionalParams ? additionalParams : {}; 4 var defaults = {}; 5 this._engine = engine; 6 this._fullEngine = additionalParams.fullEngine ? additionalParams.fullEngine : this._engine; 7 /*var defaults = { 8 center: new google.maps.LatLng(40.69847032728747, -73.9514422416687) 9 , zoom: 8 10 //, mapTypeId: google.maps.MapTypeId.ROADMAP 11 }; 12 if(params.map_center && params.map_center.coord_x && params.map_center.coord_y) { 13 params.center = new google.maps.LatLng(params.map_center.coord_x, params.map_center.coord_y); 14 } 15 if(params.zoom) { 16 params.zoom = parseInt(params.zoom); 17 } 18 if(!UMS_DATA.isAdmin && params.zoom_type == 'zoom_level' && params.zoom_mobile && jQuery(document).width() < 768) { 19 params.zoom = parseInt(params.zoom_mobile); 20 }*/ 21 /*if (typeof(elementId) === 'string') { 22 elementId = jQuery(elementId)[0]; 23 }*/ 24 this._$markerInfoWndStyle = null; 25 this._elementId = elementId; 26 this._clearElementId = str_replace(this._elementId, '#', ''); 27 this._element = typeof(elementId) === 'string' ? jQuery(elementId)[0] : elementId; 28 this._mapParams = jQuery.extend({}, defaults, mapData.params); 29 this._mapObj = null; 30 this._markers = []; 31 this._shapes = []; 32 this._heatmap = []; 33 this._kmlLayers = []; 34 this._clasterer = null; 35 this._clastererEnabled = false; 36 this._clastererMarkersGroupsStyles = []; 37 //this._eventListeners = {}; 38 //this._layers = {}; 39 //this.mapMarkersGroups = additionalData.markerGroups ? additionalData.markerGroups : []; 40 this._initComplete = false; 41 this.init(); 42} 43umsBaseMap.prototype.getEngine = function() { 44 return this._engine; 45}; 46umsBaseMap.prototype.init = function() { 47 this._beforeInit(); 48 this._createMapObj(); 49 this._refreshMarkerInfoWndStyle(); 50 this._afterInit(); 51 this._initComplete = true; 52}; 53umsBaseMap.prototype._createMapObj = function() { 54 // Map object creation for inheritance should be here 55}; 56umsBaseMap.prototype._beforeInit = function() { 57 jQuery(document).trigger('umsBeforeMapInit', this); 58}; 59umsBaseMap.prototype.getParams = function(){ 60 return this._mapParams; 61}; 62umsBaseMap.prototype.getParam = function(key){ 63 return this._mapParams[ key ]; 64}; 65umsBaseMap.prototype.setParam = function(key, value){ 66 this._mapParams[ key ] = value; 67 return this; 68}; 69umsBaseMap.prototype.resizeMapByHeight = function() { 70 if(!UMS_DATA.isAdmin && parseInt(this.getParam('adapt_map_to_screen_height')) && this.getRawMapInstance().map_display_mode != 'popup') { 71 var self = this; 72 73 function resizeHeight() { 74 var viewId = self.getParam('view_id') 75 , mapContainer = jQuery('#umsMapDetailsContainer_' + viewId) 76 , mapContainerOffset = mapContainer.length ? mapContainer.offset() : false 77 , windowHeight = jQuery(window).height(); 78 79 if(mapContainerOffset) { 80 jQuery('#umsMapDetailsContainer_' + viewId + ', #' + self.getParam('view_html_id')).each(function () { 81 var height = mapContainerOffset.top < windowHeight ? windowHeight - mapContainerOffset.top : windowHeight; 82 jQuery(this).height(height); 83 }); 84 //self.refresh(); 85 } 86 } 87 resizeHeight(); 88 jQuery(window).bind('resize', resizeHeight); 89 jQuery(window).bind('orientationchange', resizeHeight); 90 } 91}; 92umsBaseMap.prototype._afterInit = function() { 93 if(typeof(this._mapParams.marker_clasterer) !== 'undefined' && this._mapParams.marker_clasterer) { 94 this.enableClasterization(this._mapParams.marker_clasterer); 95 } 96 this.resizeMapByHeight(); 97 jQuery(document).trigger('umsAfterMapInit', this); 98}; 99umsBaseMap.prototype.addMarker = function(params) { 100 var newMarker = this._createMarkerObj(params); 101 this._markers.push( newMarker ); 102 return newMarker; 103}; 104umsBaseMap.prototype._createMarkerObj = function(params) { 105 // Marker object creation should be here 106 return umsMapLoader.initMarker(this, params) 107 //this._methodRedefineNotice('umsBaseMap.prototype.setCenter'); 108 //return null; 109}; 110umsBaseMap.prototype.getMarkerById = function(id) { 111 if(this._markers && this._markers.length) { 112 id = parseInt(id); 113 for(var i in this._markers) { 114 if(this._markers[i].getId && this._markers[i].getId() === id) 115 return this._markers[ i ]; 116 } 117 } 118 return false;
119}; 120umsBaseMap.prototype.removeMarker = function(id) { 121 var marker = this.getMarkerById( id ); 122 if(marker) { 123 marker.removeFromMap(); 124 } 125}; 126umsBaseMap.prototype.getAllMarkers = function() { 127 return this._markers; 128}; 129umsBaseMap.prototype.addEventListener = function(event, callback) { 130 /*zoom_changed, dragend*/ 131 this._methodRedefineNotice('umsBaseMap.prototype.addEventListener'); 132}; 133umsBaseMap.prototype.setCenter = function (lat, lng) { 134 this._methodRedefineNotice('umsBaseMap.prototype.setCenter'); 135}; 136umsBaseMap.prototype.getCenter = function () { 137 this._methodRedefineNotice('umsBaseMap.prototype.getCenter'); 138}; 139umsBaseMap.prototype.setZoom = function (zoomLevel) { 140 this._methodRedefineNotice('umsBaseMap.prototype.setZoom'); 141}; 142umsBaseMap.prototype.getZoom = function () { 143 this._methodRedefineNotice('umsBaseMap.prototype.getZoom'); 144}; 145umsBaseMap.prototype.setMapType = function (mapType) { 146 this._methodRedefineNotice('umsBaseMap.prototype.setMapType'); 147}; 148/** 149 * Should trigger after added or modified markers 150 */ 151umsBaseMap.prototype.markersRefresh = function() { 152 var clasterer = this.getClasterer(); 153 154 if(this._clastererEnabled && clasterer) { 155 this._refreshCluster(); 156 /*clasterer.clearMarkers(); 157 clasterer.addMarkers( this.getAllRawMarkers() );*/ 158 } 159 jQuery(document).trigger('umsAfterMarkersRefresh', this); 160}; 161umsBaseMap.prototype._refreshCluster = function() { 162 this._methodRedefineNotice('umsBaseMap.prototype._refreshCluster'); 163}; 164umsBaseMap.prototype.getAllRawMarkers = function() { 165 var res = []; 166 if(this._markers && this._markers.length) { 167 for(var i = 0; i < this._markers.length; i++) { 168 res.push( this._markers[i].getRawMarkerInstance() ); 169 } 170 } 171 return res; 172}; 173 174umsBaseMap.prototype._methodRedefineNotice = function(methodName) { 175 console.log('['+ methodName+ '] should be re-defined!'); 176}; 177umsBaseMap.prototype.clearMarkers = function() { 178 if(this._markers && this._markers.length) { 179 for(var i = 0; i < this._markers.length; i++) { 180 this._markers[i].removeFromMap(); 181 } 182 this._markers = []; 183 } 184}; 185umsBaseMap.prototype.clearMarkersByParam = function(param) { 186 if(this._markers && this._markers.length) { 187 for(var i = 0; i < this._markers.length; i++) { 188 if(this._markers[i].getMarkerParam(param)) { 189 this._markers[i].removeFromMap(); 190 this._markers.splice(i, 1); 191 this.clearMarkersByParam(param); 192 break; 193 } 194 } 195 } 196}; 197umsBaseMap.prototype._runAfterInitComplete = function(clb) { 198 // TODO: think and write 199}; 200umsBaseMap.prototype.setNavigationBarMode = function(mode) { 201 this._methodRedefineNotice('umsBaseMap.prototype.setNavigationBarMode'); 202}; 203umsBaseMap.prototype.getNavigationBarMode = function() { 204 this._methodRedefineNotice('umsBaseMap.prototype.getNavigationBarMode'); 205}; 206umsBaseMap.prototype.enbZoom = function(mode) { 207 this._methodRedefineNotice('umsBaseMap.prototype.enbZoom'); 208}; 209umsBaseMap.prototype.enbDraggable = function(mode) { 210 this._methodRedefineNotice('umsBaseMap.prototype.enbDraggable'); 211}; 212umsBaseMap.prototype.enbWheelZoom = function(mode) { 213 this._methodRedefineNotice('umsBaseMap.prototype.enbWheelZoom'); 214}; 215umsBaseMap.prototype.geocodeQuery = function(search, clb) { 216 this._methodRedefineNotice('umsBaseMap.prototype.geocodeQuery'); 217}; 218 219umsBaseMap.prototype.getClasterer = function() { 220 if(this._clasterer) { 221 return this._clasterer; 222 } 223 return false; 224}; 225umsBaseMap.prototype.setClasterer = function(clasterer) { 226 this._clasterer = clasterer; 227}; 228 229umsBaseMap.prototype.geocodeSearchAutocomplete = function($el, params) { 230 params = params || {}; 231 var mapSelf = this; 232 $el = typeof($el) === 'string' ? jQuery($el) : $el; 233 $el.keyup(function(event){ 234 // Ignore tab, enter, caps, end, home, arrows 235 if(toeInArrayUms(event.keyCode, [9, 13, 20, 35, 36, 37, 38, 39, 40])) return; 236 237 var searchData = jQuery.trim(jQuery(this).val()); 238 239 if(searchData && searchData != '') { 240 if(typeof(params.msgEl) === 'string') { 241 params.msgEl = jQuery(params.msgEl); 242 } 243 params.msgEl.showLoaderUms(); 244 var self = this; 245 246 jQuery(this).autocomplete({ 247 source: function(request, response) { 248 var autocomleateData = typeof(params.additionalData) != 'undefined' 249 ? umsAutocomleateData(params.additionalData, request.term) 250 : [] 251 252 mapSelf.geocodeQuery(searchData, function(results) { 253 params.msgEl.html(''); 254 for(var i = 0; i < results.length; i++) { 255 autocomleateData.push({ 256 label: results[i].formatted_address 257 , lat: results[i].lat 258 , lng: results[i].lng 259 }); 260 } 261 response(autocomleateData); 262 }, function(event) { 263 if(autocomleateData && autocomleateData.length > 0) { 264 response(autocomleateData); 265 } else { 266 //var notFoundMsg = toeLangUms('Google can\'t find requested address coordinates, please try to modify search criterias.'); 267 var notFoundMsg = toeLangUms('Nothing was found'); 268 269 if(jQuery(self).parent().find('.ui-helper-hidden-accessible').length) { 270 jQuery(self).parent().find('.ui-helper-hidden-accessible').html(notFoundMsg); 271 } else { 272 params.msgEl.html(notFoundMsg); 273 } 274 } 275 }); 276 } 277 , select: function(event, ui) { 278 if(params.onSelect) { 279 params.onSelect(ui.item, event, ui); 280 } 281 jQuery(self).removeClass('ui-autocomplete-loading'); 282 } 283 }); 284 285 // Force imidiate search right after creation 286 jQuery(this).autocomplete('search'); 287 } 288 }); 289 function umsAutocomleateData(data, needle) { 290 var autocomleateData = []; 291 292 for(var i = 0; i < data.length; i++) { 293 for(var j = 0; j < data[i].length; j++) { 294 if(data[i][j]) { 295 var label = data[i][j].label.toString().toLowerCase() 296 , desc = data[i][j].marker_desc != 'undefined' ? data[i][j].marker_desc : '' 297 , term = needle.toLowerCase(); 298 299 if(label.indexOf(term) !== -1 || (desc && desc.indexOf(term) !== -1)) { 300 autocomleateData.push(data[i][j]); 301 } 302 } 303 } 304 } 305 return autocomleateData; 306 } 307}; 308umsBaseMap.prototype.getRawMapInstance = function() { 309 return this._mapObj; 310}; 311umsBaseMap.prototype.checkMarkersParams = function(markers, needToShow) { 312 if(markers && markers.length) { 313 for (var i = 0; i < markers.length; i++) { 314 var markerParams = markers[i].getMarkerParam('params') 315 , showDescription = parseInt(markerParams.show_description); 316 if(showDescription || needToShow) { 317 markers[i].showInfoWnd( true, showDescription, true ); 318 } 319 } 320 } 321}; 322umsBaseMap.prototype.setMarkerInfoWndWidthUnits = function(type) { 323 this.setParam('marker_infownd_width_units', type); 324 this._refreshMarkerInfoWndStyle(); 325}; 326umsBaseMap.prototype.setMarkerInfoWndWidth = function(width) { 327 this.setParam('marker_infownd_width', width); 328 this._refreshMarkerInfoWndStyle(); 329}; 330umsBaseMap.prototype.setMarkerInfoWndHeightUnits = function(type) { 331 this.setParam('marker_infownd_height_units', type); 332 this._refreshMarkerInfoWndStyle(); 333}; 334umsBaseMap.prototype.setMarkerInfoWndHeight = function(height) { 335 this.setParam('marker_infownd_height', height); 336 this._refreshMarkerInfoWndStyle(); 337}; 338 339umsBaseMap.prototype.setMarkerInfoWndTitleColor = function(color) { 340 this.setParam('marker_title_color', color); 341 this._refreshMarkerInfoWndStyle(); 342}; 343umsBaseMap.prototype.setMarkerInfoWndBgColor = function(color) { 344 this.setParam('marker_infownd_bg_color', color); 345 this._refreshMarkerInfoWndStyle(); 346}; 347umsBaseMap.prototype.setMarkerInfoWndTitleSize = function(size) { 348 this.setParam('marker_title_size', size); 349 this._refreshMarkerInfoWndStyle(); 350}; 351umsBaseMap.prototype.setMarkerInfoWndDescSize = function(size) { 352 this.setParam('marker_desc_size', size); 353 this._refreshMarkerInfoWndStyle(); 354}; 355umsBaseMap.prototype._refreshMarkerInfoWndStyle = function() { 356 var styleHtml = this._generateMarkerInfoWndStyle(); 357 if(!styleHtml) return; 358 if(!this._$markerInfoWndStyle) { 359 this._$markerInfoWndStyle = jQuery('<style id="umsMarkerInfoWndStyle_'+ this._clearElementId+ '">').appendTo('body'); 360 } 361 this._$markerInfoWndStyle.html( styleHtml ); 362}; 363umsBaseMap.prototype._generateMarkerInfoWndStyle = function() {
364 //this._methodRedefineNotice('umsBaseMap.prototype._generateMarkerInfoWndStyle'); 365 // If map require generate style - it should re-define this 366 return false; 367}; 368umsBaseMap.prototype._getCreateCoords = function() { 369 return this._mapParams.map_center 370 && this._mapParams.map_center.coord_x && this._mapParams.map_center.coord_x !== '' 371 && this._mapParams.map_center.coord_y && this._mapParams.map_center.coord_y !== '' 372 ? this._mapParams.map_center 373 : {coord_x: 51.50632, coord_y: -0.12714}; 374}; 375umsBaseMap.prototype.enableClasterization = function(clasterType, needTrigger) { 376 this._clastererEnabled = true; 377}; 378umsBaseMap.prototype.disableClasterization = function() { 379 this._clastererEnabled = false; 380}; 381umsBaseMap.prototype.setClusterSize = function(size) { 382 this._methodRedefineNotice('umsBaseMap.prototype.geocodeQuery'); 383}; 384umsBaseMap.prototype.getViewId = function() { 385 return this._mapParams.view_id; 386}; 387umsBaseMap.prototype.getViewHtmlId = function() { 388 return this._mapParams.view_html_id; 389}; 390umsBaseMap.prototype.getId = function() { 391 return this._mapParams.id; 392}; 393umsBaseMap.prototype.closeAllInfoWnd = function() { 394 if(this._markers && this._markers.length) { 395 for (var i = 0; i < this._markers.length; i++) { 396 this._markers[i].hideInfoWnd(); 397 } 398 } 399}; 400umsBaseMap.prototype.clearShapes = function() { 401 if(this._shapes && this._shapes.length) { 402 for(var i = 0; i < this._shapes.length; i++) { 403 this._shapes[i].setMap( null ); 404 } 405 this._shapes = []; 406 } 407}; 408umsBaseMap.prototype.addShape = function(params) { 409 var newShape = umsShapeLoader.initShape(this, params); 410 this._shapes.push( newShape ); 411 return newShape; 412}; 413umsBaseMap.prototype.addHeatmap = function(params) { 414 //var heatmap = new umsGoogleHeatmap(this, params); 415 // TODO: Add here heatmap object generation 416 this._heatmap.push( heatmap ); 417 return heatmap; 418}; 419 420umsBaseMap.prototype.getShapeById = function(id) { 421 if(this._shapes && this._shapes.length) { 422 for(var i in this._shapes) { 423 if(this._shapes[ i ].getId() == id) 424 return this._shapes[ i ]; 425 } 426 } 427 return false; 428}; 429umsBaseMap.prototype.getHeatmap = function() { 430 if(this._heatmap && this._heatmap.length) { 431 // There is only one heatmap layer on the map 432 return this._heatmap[0]; 433 } 434 return false; 435}; 436 437umsBaseMap.prototype.removeShape = function(id) { 438 var shape = this.getShapeById( id ); 439 if(shape) { 440 shape.removeFromMap(); 441 } 442}; 443 444umsBaseMap.prototype.getAllShapes = function() { 445 return this._shapes; 446}; 447umsBaseMap.prototype.addKmlLayer = function(layer) { 448 this._kmlLayers.push(layer); 449}; 450umsBaseMap.prototype.removeKmlLayerByUrl = function(url) { 451 if(this._kmlLayers.length) { 452 for(var i = 0; i < this._kmlLayers.length; i++) { 453 if(this._kmlLayers[ i ].getUrl() == url) { 454 this._kmlLayers[ i ].removeFromMap(); 455 this._kmlLayers.splice(i, 1); 456 break; 457 } 458 } 459 } 460}; 461umsBaseMap.prototype._setMinZoomLevel = function() { 462 var curZoom = this.getZoom(); 463 var minZoom = parseInt(this._mapParams.zoom_min) ? parseInt(this._mapParams.zoom_min) : null; 464 //this.getRawMapInstance().setOptions({minZoom: minZoom}); 465 if(curZoom < minZoom) 466 this.setZoom(minZoom); 467}; 468umsBaseMap.prototype._setMaxZoomLevel = function() { 469 var maxZoom = parseInt(this._mapParams.zoom_max) ? parseInt(this._mapParams.zoom_max) : null; 470 //this.getRawMapInstance().setOptions({maxZoom: maxZoom}); 471 if(this.getRawMapInstance().zoom > maxZoom) 472 this.setZoom(maxZoom); 473}; 474/*umsBaseMap.prototype._fixZoomLevel = function() { 475 var eventHandle = this._getEventListenerHandle('zoom_changed', 'zoomChanged'); 476 if(!eventHandle) { 477 eventHandle = google.maps.event.addListener(this.getRawMapInstance(), 'zoom_changed', jQuery.proxy(function(){ 478 var minZoom = parseInt(this.getParam('zoom_min')) 479 , maxZoom = parseInt(this.getParam('zoom_max')); 480 if (this.getZoom() < minZoom) { 481 this.setZoom(minZoom); 482 if(GMP_DATA.isAdmin && this._getEventListenerHandle('idle', 'enableClasterization')) 483 google.maps.event.trigger(this.getRawMapInstance(), 'idle'); 484 } 485 if (this.getZoom() > maxZoom) { 486 this.setZoom(maxZoom); 487 if(GMP_DATA.isAdmin && this._getEventListenerHandle('idle', 'enableClasterization')) 488 google.maps.event.trigger(this.getRawMapInstance(), 'idle'); 489 } 490 }, this)); 491 this._addEventListenerHandle('zoom_changed', 'zoomChanged', eventHandle); 492 } 493};*/ 494var umsMapLoader = { 495 initMap: function(elementId, mapData, additionalParams) { 496 var engine = umsGetMapsEngine(mapData); 497 additionalParams = additionalParams ? additionalParams : {}; 498 additionalParams.fullEngine = umsGetMapsFullEngine(mapData); 499 return new window['ums'+ toeStrFirstUp(engine)+ 'Map'](elementId, mapData, engine, additionalParams); 500 } 501, initMarker: function(map, markerParams) {
502 return new window['ums'+ toeStrFirstUp(map.getEngine())+ 'Marker'](map, markerParams); 503 } 504}; 505var g_umsMapLoadObserver = { 506 _loaded: {} 507, setLoaded: function(engine) { 508 this._loaded[ engine ] = true; 509 } 510, isLoaded: function(engine) { 511 return this._loaded[ engine ]; 512 } 513, trigger: function(engine, clb) { 514 if(this.isLoaded(engine)) { 515 clb(); 516 } else { 517 var self = this; 518 setTimeout(function(){ 519 self.trigger(engine, clb); 520 }, 500); 521 } 522 } 523}; 524function umsGetMapsEngine(map) { 525 var fullEngine = umsGetMapsFullEngine(map); 526 if(fullEngine.indexOf('l-') === 0) { 527 return 'leaflet'; 528 } 529 return fullEngine; 530} 531function umsGetMapsFullEngine(map) { 532 // This can be object inherited from umsBaseMap 533 if(map && typeof(map.getEngine) === 'function') { 534 return map.getEngine(); 535 } 536 // Or just map set from database 537 if(map && map.engine && map.engine !== '') { 538 return map.engine; 539 } 540 return UMS_DATA.engine; 541} 542function gmpAutocomleateData(data, needle) { 543 var autocomleateData = []; 544 545 for(var i = 0; i < data.length; i++) { 546 for(var j = 0; j < data[i].length; j++) { 547 if(data[i][j]) { 548 var label = data[i][j].label.toString().toLowerCase() 549 , desc = data[i][j].marker_desc != 'undefined' ? data[i][j].marker_desc : '' 550 , term = needle.toLowerCase(); 551 552 if(label.indexOf(term) !== -1 || (desc && desc.indexOf(term) !== -1)) { 553 autocomleateData.push(data[i][j]); 554 } 555 } 556 } 557 } 558 return autocomleateData; 559}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.