 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.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.enableGoogleBar) this._gmap.enableGoogleBar(); 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.setupCenter(point); }); } else this.setupCenter(new GLatLng(this._config.lat, this._config.lng)); } } }, setupCenter: 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.callback) try { var handler = eval(this._config.callback); handler(point.lat(), point.lng()); } catch(ex) { } 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.setupClickHandler(); }, setupClickHandler: function() { if(this._config.showClientClickPosition){ try { var handler = (this._config.clientClickHandler) ? eval(this._config.clientClickHandler) : function(overlay, position){ if(position) alert('Map Possion\n\tLatitude: ' + position.lat() + '\n\tLongitude: ' + position.lng()); }; GEvent.addListener(this._gmap, 'click', handler); } catch(ex){} } 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(marker) { GEvent.addListener(marker, "click", function() { marker.openInfoWindowHtml(config.text); }); this._gmap.addOverlay(marker); } if(config.field) { var field = document.getElementById(config.field); if(field) { field.value = point.lat() + ";" + point.lng(); } } if(config.callback) try { var handler = eval(config.callback); handler(point.lat(), point.lng()); } catch(ex1) { } } catch(ex) { } this.setupMarker(++this._index); }, setupDirections: function() { var config; for(config in this._gdirections) { try { 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]); } } } };
