 if(!Artem) var Artem = {}; if(!Artem.Web) Artem.Web = {}; Artem.Web.GoogleMapManager = { _disposed: false, Maps : new Array(), Geocoder : new GClientGeocoder(), addMap: function(map) { Artem.Web.GoogleMapManager.Maps[map._elementId] = map; }, dispose: function() { if(!Artem.Web.GoogleMapManager._disposed) { GUnload(); Artem.Web.GoogleMapManager._disposed = true; } }, initialize: function() { if (GBrowserIsCompatible()) { Artem.Web.GoogleMapManager._disposed = false; document.body.onunload = Artem.Web.GoogleMapManager.dispose; } } }; Artem.Web.GoogleMapView = { Normal: 0, Satellite: 1, Hybrid: 2, Physical: 3, MoonElevation: 4, MoonVisible: 5, MarsElevation: 6, MarsVisible: 7, MarsInfrared: 8, SkyVisible: 9 }; Artem.Web.GoogleMarkerInfoEvent = { Click: 0, DoubleClick: 1, MouseDown: 2, MouseOut: 3, MouseOver: 4, MouseUp: 5 }; Artem.Web.GoogleMap = function(elementId, config) { this._config = config; this._elementId = elementId; this._gmap = null; this._gmarkers = null; this._gdirections = null; this._gpolylines = null; this._gpolygons = null; this._index = 0; this._markerManager; Artem.Web.GoogleMapManager.addMap(this); }; Artem.Web.GoogleMap.prototype = { get_Center: function() { return new GLatLng(this._config.lat, this._config.lng); }, get_Element: function() { return document.getElementById(this._elementId); }, get_ElementId: function() { return this._elementId; }, get_GMap: function() { return this._gmap; }, get_MarkerManager: function() { return this._markerManager; }, get_Options: function() { return this._config; }, addMarker: function(config) { if(!this._gmarkers) this._gmarkers = new Array(); this._gmarkers[this._gmarkers.length] = config; }, addDirection: function(config) { if(!this._gdirections) this._gdirections = new Array(); this._gdirections[this._gdirections.length] = config; }, addPolyline: function(config) { if(!this._gpolylines) this._gpolylines = new Array(); this._gpolylines[this._gpolylines.length] = config; }, addPolygon: function(config) { if(!this._gpolygons) this._gpolygons = new Array(); this._gpolygons[this._gpolygons.length] = config; }, createIcon: function(options) { var icon = null; if(options.image) { icon = new GIcon(G_DEFAULT_ICON); icon.image = options.image; if(options.imageWidth && options.imageHeight) icon.iconSize = new GSize(options.imageWidth, options.imageHeight); if(options.shadow) icon.shadow = options.shadow; if(options.shadowWidth && options.shadowHeight) icon.shadowSize = new GSize(options.shadowWidth, options.shadowHeight); } return icon; }, load: function() { if (GBrowserIsCompatible()) { var mapOptions; if(this._config.width && this._config.height) mapOptions = {size: new GSize(this._config.width, this._config.height)}; this._gmap = new GMap2(this.get_Element(), mapOptions); if(this._gmap) { if(this._config.zoomPanType && this._config.zoomPanType == 1) this._gmap.addControl(new GLargeMapControl()); else this._gmap.addControl(new GSmallMapControl()); if(this._config.typeControl) this._gmap.addControl(new GMapTypeControl()); if(this._config.baseCountryCode) Artem.Web.GoogleMapManager.Geocoder.setBaseCountryCode(this._config.baseCountryCode); if(this._config.enableGoogleBar) this._gmap.enableGoogleBar(); if(this._config.enableScrollWheelZoom) this._gmap.enableScrollWheelZoom(); if(this._config.enableMarkerManager) this._markerManager = new MarkerManager(this._gmap); if(this._config.traffic) this._gmap.addOverlay(new GTrafficOverlay()); if(this._config.address) { var map = this; Artem.Web.GoogleMapManager.Geocoder.getLatLng( this._config.address, function(point) { map.setup(point); }); } else this.setup(new GLatLng(this._config.lat, this._config.lng)); } } }, setup: function(point) { this._gmap.setCenter(point, this._config.zoom); if(this._config.text) this._gmap.openInfoWindow(point, this._config.text); if(this._config.field) { var field = document.getElementById(this._config.field); if(field) { field.value = point.lat() + ";" + point.lng(); } } if(this._config.events) { var handler; var config = this._config; if(config.events.click) { handler = function(overlay, point) { eval(config.events.click).call(this, overlay, point); }; GEvent.addListener(this._gmap, "click", handler); } if(config.events.dblclick) { handler = function(overlay, point) { eval(config.events.dblclick).call(this, overlay, point); }; GEvent.addListener(this._gmap, "dblclick", handler); } if(config.events.drag) { handler = function() { eval(config.events.drag).call(this); }; GEvent.addListener(this._gmap, "drag", handler); } if(config.events.dragend) { handler = function() { eval(config.events.dragend).call(this); }; GEvent.addListener(this._gmap, "dragend", handler); } if(config.events.dragstart) { handler = function() { eval(config.events.dragstart).call(this); }; GEvent.addListener(this._gmap, "dragstart", handler); } if(config.events.geoload && config.field) { if(config.events.geoload.match("__doPostBack")) handler = function(lat, lng) { eval(config.events.geoload); }; else handler = function(lat, lng) { eval(config.events.geoload).call(this, lat, lng); }; handler(point.lat(), point.lng()); } if(config.events.infowindowbeforeclose) { handler = function() { eval(config.events.infowindowbeforeclose).call(this); }; GEvent.addListener(this._gmap, "infowindowbeforeclose", handler); } if(config.events.infowindowclose) { handler = function() { eval(config.events.infowindowclose).call(this); }; GEvent.addListener(this._gmap, "infowindowclose", handler); } if(config.events.infowindowopen) { handler = function() { eval(config.events.infowindowopen).call(this); }; GEvent.addListener(this._gmap, "infowindowopen", handler); } if(config.events.load) { handler = function() { eval(config.events.load).call(this); }; GEvent.addListener(this._gmap, "load", handler); } if(config.events.addmaptype) { handler = function(type) { eval(config.events.addmaptype).call(this, type); }; GEvent.addListener(this._gmap, "addmaptype", handler); } if(config.events.maptypechanged) { handler = function() { eval(config.events.maptypechanged).call(this); }; GEvent.addListener(this._gmap, "maptypechanged", handler); } if(config.events.removemaptype) { handler = function(type) { eval(config.events.removemaptype).call(this, type); }; GEvent.addListener(this._gmap, "removemaptype", handler); } if(config.events.mousemove) { handler = function(latlng) { eval(config.events.mousemove).call(this, latlng); }; GEvent.addListener(this._gmap, "mousemove", handler); } if(config.events.mouseout) { handler = function(latlng) { eval(config.events.mouseout).call(this, latlng); }; GEvent.addListener(this._gmap, "mouseout", handler); } if(config.events.mouseover) { handler = function(latlng) { eval(config.events.mouseover).call(this, latlng); }; GEvent.addListener(this._gmap, "mouseover", handler); } if(config.events.move) { handler = function() { eval(config.events.move).call(this); }; GEvent.addListener(this._gmap, "move", handler); } if(config.events.moveend) { handler = function() { eval(config.events.moveend).call(this); }; GEvent.addListener(this._gmap, "moveend", handler); } if(config.events.movestart) { handler = function() { eval(config.events.movestart).call(this); }; GEvent.addListener(this._gmap, "movestart", handler); } if(config.events.addoverlay) { handler = function(overlay) { eval(config.events.addoverlay).call(this, overlay); }; GEvent.addListener(this._gmap, "addoverlay", handler); } if(config.events.removeoverlay) { handler = function(overlay) { eval(config.events.removeoverlay).call(this, overlay); }; GEvent.addListener(this._gmap, "removeoverlay", handler); } if(config.events.clearoverlays) { handler = function() { eval(config.events.clearoverlays).call(this); }; GEvent.addListener(this._gmap, "clearoverlays", handler); } if(config.events.singlerightclick) { handler = function(point, src, overlay) { eval(config.events.singlerightclick).call(this, point, src, overlay); }; GEvent.addListener(this._gmap, "singlerightclick", handler); } if(config.events.zoomend) { handler = function(oldLevel, newLevel) { eval(config.events.zoomend).call(this, oldLevel, newLevel); }; GEvent.addListener(this._gmap, "zoomend", handler); } } this.setupMapView(); }, setupMapView: function() { if(this._config.view) { switch(this._config.view) { case Artem.Web.GoogleMapView.Normal: this._gmap.setMapType(G_NORMAL_MAP); break; case Artem.Web.GoogleMapView.Satellite: this._gmap.setMapType(G_SATELLITE_MAP); break; case Artem.Web.GoogleMapView.Hybrid: this._gmap.setMapType(G_HYBRID_MAP); break; case Artem.Web.GoogleMapView.Physical: this._gmap.addMapType(G_PHYSICAL_MAP); this._gmap.setMapType(G_PHYSICAL_MAP); break; case Artem.Web.GoogleMapView.MoonElevation: this._gmap.addMapType(G_MOON_ELEVATION_MAP); this._gmap.setMapType(G_MOON_ELEVATION_MAP); break; case Artem.Web.GoogleMapView.MoonVisible: this._gmap.addMapType(G_MOON_VISIBLE_MAP); this._gmap.setMapType(G_MOON_VISIBLE_MAP); break; case Artem.Web.GoogleMapView.MarsElevation: this._gmap.addMapType(G_MARS_ELEVATION_MAP); this._gmap.setMapType(G_MARS_ELEVATION_MAP); break; case Artem.Web.GoogleMapView.MarsVisible: this._gmap.addMapType(G_MARS_VISIBLE_MAP); this._gmap.setMapType(G_MARS_VISIBLE_MAP); break; case Artem.Web.GoogleMapView.MarsInfrared: this._gmap.addMapType(G_MARS_INFRARED_MAP); this._gmap.setMapType(G_MARS_INFRARED_MAP); break; case Artem.Web.GoogleMapView.SkyVisible: this._gmap.addMapType(G_SKY_VISIBLE_MAP); this._gmap.setMapType(G_SKY_VISIBLE_MAP); break; } } this.setupMarkers(); }, setupMarkers: function() { this.setupMarker(this._index = 0); }, setupMarker: function(index) { if(this._gmarkers && this._gmarkers[index]) { var config = this._gmarkers[index]; if(config.address) { var map = this; Artem.Web.GoogleMapManager.Geocoder.getLatLng( config.address, function(point) { map.setupMarkerItem(point); }); } else this.setupMarkerItem(new GLatLng(config.lat, config.lng)); } else this.setupDirections(); }, setupMarkerItem: function(point) { try { var config = this._gmarkers[this._index]; var markerOptions = {draggable: config.draggable, icon: null}; markerOptions.icon = this.createIcon(config); var marker = new GMarker(point, markerOptions); if(config.field) { var field = document.getElementById(config.field); if(field) { field.value = point.lat() + ";" + point.lng(); } } if(marker) { var eventName = "click"; if(!config.events || !config.events.click) { switch(config.infoWindowEvent) { case Artem.Web.GoogleMarkerInfoEvent.Click: eventName = "click"; break; case Artem.Web.GoogleMarkerInfoEvent.DoubleClick: eventName = "dblclick"; break; case Artem.Web.GoogleMarkerInfoEvent.MouseDown: eventName = "mousedown"; break; case Artem.Web.GoogleMarkerInfoEvent.MouseOut: eventName = "mouseout"; break; case Artem.Web.GoogleMarkerInfoEvent.MouseOver: eventName = "mouseover"; break; case Artem.Web.GoogleMarkerInfoEvent.MouseUp: eventName = "mouseup"; break; } GEvent.addListener(marker, eventName, function() { marker.openInfoWindowHtml(config.text); }); } this.setupMarkerEvents(marker, config); this._gmap.addOverlay(marker); } } catch(ex) { } this.setupMarker(++this._index); }, setupMarkerEvents: function(marker, config) { if(config.events) { var handler; if(config.events.click) { handler = function() { eval(config.events.click).call(this); }; GEvent.addListener(marker, "click", handler); } if(config.events.dblclick) { handler = function() { eval(config.events.dblclick).call(this); }; GEvent.addListener(marker, "dblclick", handler); } if(config.events.drag) { handler = function() { eval(config.events.drag).call(this); }; GEvent.addListener(marker, "drag", handler); } if(config.events.dragend) { handler = function() { eval(config.events.dragend).call(this); }; GEvent.addListener(marker, "dragend", handler); } if(config.events.dragstart) { handler = function() { eval(config.events.dragstart).call(this); }; GEvent.addListener(marker, "dragstart", handler); } if(config.events.geoload && config.field) { if(config.events.geoload.match("__doPostBack")) handler = function(lat, lng) { eval(config.events.geoload); }; else handler = function(lat, lng) { eval(config.events.geoload).call(this, lat, lng); }; handler(point.lat(), point.lng()); } if(config.events.infowindowbeforeclose) { handler = function() { eval(config.events.infowindowbeforeclose).call(this); }; GEvent.addListener(marker, "infowindowbeforeclose", handler); } if(config.events.infowindowclose) { handler = function() { eval(config.events.infowindowclose).call(this); }; GEvent.addListener(marker, "infowindowclose", handler); } if(config.events.infowindowopen) { handler = function() { eval(config.events.infowindowopen).call(this); }; GEvent.addListener(marker, "infowindowopen", handler); } if(config.events.mousedown) { handler = function() { eval(config.events.mousedown).call(this); }; GEvent.addListener(marker, "mousedown", handler); } if(config.events.mouseout) { handler = function() { eval(config.events.mouseout).call(this); }; GEvent.addListener(marker, "mouseout", handler); } if(config.events.mouseover) { handler = function() { eval(config.events.mouseover).call(this); }; GEvent.addListener(marker, "mouseover", handler); } if(config.events.mouseup) { handler = function() { eval(config.events.mouseup).call(this); }; GEvent.addListener(marker, "mouseup", handler); } if(config.events.remove) { handler = function() { eval(config.events.remove).call(this); }; GEvent.addListener(marker, "remove", handler); } if(config.events.visibilitychanged) { handler = function(isVisible) { eval(config.events.visibilitychanged).call(this, isVisible); }; GEvent.addListener(marker, "visibilitychanged", handler); } } }, setupDirections: function() { if(this._gdirections) { var i, config; for(i = 0; i < this._gdirections.length; i ++) { try { config = this._gdirections[i]; var directionsPanel = document.getElementById(config.routePanelId); var directions = new GDirections(this._gmap, directionsPanel); directions.load(config.text); } catch(ex){} } } this.setupPolylines(); }, setupPolylines: function() { if(this._gpolylines) { var i; for(i = 0; i < this._gpolylines.length; i++) { this._gmap.addOverlay(this._gpolylines[i]); } } this.setupPolygons(); }, setupPolygons: function() { if(this._gpolygons) { var i; for(i = 0; i < this._gpolygons.length; i++) { this._gmap.addOverlay(this._gpolygons[i]); } } } };