// $Id: cck_map.js,v 1.8 2008/01/09 02:54:07 beeradb Exp $ /* CLASS: gMapBaseController * DESCRIPTION: handles shared functionality between the admin and client controllers */ gmapBaseController = function () {}; gmapBaseController.prototype.initializeMap = function(lat, lon, zoom, mapType){ if (lon != 0 && lat != 0 && zoom != 0){ this.map.setCenter(new GLatLng(lat, lon), zoom); //this.map.setCenter(new GLatLng(180, 180), 3); }else{ this.map.setCenter(new GLatLng(0, 0), 1); } if (mapType.length){ if (mapType.length > 0){ this.map.setMapType(eval(mapType)); } } this.map.addControl(new GLargeMapControl()); this.map.addControl(new GMapTypeControl()); }; gmapBaseController.prototype.getMarkerOptions = function(img){ var baseIcon = new GIcon(); baseIcon.iconSize = new GSize(20, 34); baseIcon.iconAnchor = new GPoint(9, 34); baseIcon.infoWindowAnchor = new GPoint(9, 2); baseIcon.infoShadowAnchor = new GPoint(18, 25); if (img.length){ var i = new GIcon(baseIcon); i.image = 'http://'+this.tld+'/'+img; markerOptions = { icon:i }; }else{ markerOptions = { }; } return markerOptions; }; /* * CLASS: gmapClientController * DESCRIPTION: */ gmapClientController.prototype = new gmapBaseController(); gmapClientController.contructor = gmapClientController; function gmapClientController(prefix, lat, lon, zoom, mapType, markers, tld) { this.prefix = prefix; this.lat = lat; this.lon = lon; this.zoom = zoom; this.mapType = mapType; this.tld = tld; this.markerList = new Array(); this.markers = markers; this.map = new GMap2(document.getElementById(prefix +"mapArea")); this.initializeMap(); this.initializePoints(); } gmapClientController.prototype.initializeMap = function(){ gmapBaseController.prototype.initializeMap.call(this, this.lat, this.lon, this.zoom, this.mapType); } gmapClientController.prototype.xmlToPoints = function(){ gmapBaseController.prototype.xmlToPoints.call(this, this.points, false); } gmapClientController.prototype.getInfoWindowHtml = function (m){ var ret = ''; if (m.title) ret += "

"+ m.title +"

"; if (m.description) ret += "

"+ m.description +"

"; return ret; } gmapClientController.prototype.initializePoints = function(){ jsString = this.prefix.replace('-', '_', 'g'); for (i=0;i 0) controller.map.removeOverlay(controller.markerList[0]); img = null; if (img = controller.getCurrentMarkerImage()){ markerOptions = controller.getMarkerOptions(img); }else{ markerOptions = controller.getMarkerOptions(''); } markerOptions.draggable = true; controller.marker = new GMarker(point, markerOptions); controller.attachMarkerListeners(controller.marker); controller.marker.image = img; controller.map.addOverlay(controller.marker); if (controller.editTarget != -1){ if (controller.useMultiple) controller.map.removeOverlay(controller.markerList[controller.editTarget]); controller.cancelEdit(); } controller.serializeAll(); } } }); GEvent.addListener(this.map, 'maptypechanged', function(){ controller.serializeMap(); }); GEvent.addListener(this.map, 'moveend', function(){ controller.serializeMap(); }); GEvent.addListener(this.map, 'zoomend', function(){ controller.serializeMap(); }); GEvent.addListener(this.map,'dragend', function(){ controller.serializeMap(); }); }; gmapAdminController.prototype.muteNonEditMarkers = function () { if (this.editTarget != -1) for (var i=0;iSave Marker | Remove Marker | Cancel"; } } gmapAdminController.prototype.saveEdit = function(){ if (this.editTarget != -1){ m = this.markerList[this.editTarget]; if (this.useImage){ if (img = this.getCurrentMarkerImage()){ if (img != m.image){ markerOptions = this.getMarkerOptions(img); markerOptions.draggable = true; newMarker = new GMarker(m.getPoint(), markerOptions); newMarker.image = img; this.map.addOverlay(newMarker); this.map.removeOverlay(m); }else{ m.description = this.getCurrentDescription(); m.title = this.getCurrentTitle(); this.serializeMapPoints(); } } }else{ m.description = this.getCurrentDescription(); m.title = this.getCurrentTitle(); this.serializeMapPoints(); } this.cancelEdit(); } } gmapAdminController.prototype.removeTarget = function(){ this.restoreMarkerImages(); if (this.editTarget != -1){ this.map.removeOverlay(this.markerList[this.editTarget]); this.serializeMapPoints(); this.cancelEdit(); } } gmapAdminController.prototype.cancelEdit = function(){ if (this.useTitle || this.useDescription || this.useImage){ if (this.useTitle) document.getElementById('edit-'+this.prefix+'-markerTitle').value = ''; if (this.useDescription) document.getElementById('edit-'+this.prefix+'-markerDescription').value = ''; jsString = this.prefix.replace('-', '_'); document.getElementById(this.prefix+'editControls').innerHTML = ''; } this.restoreMarkerImages(); this.editTarget = -1; } gmapAdminController.prototype.xmlToPoints = function xml(xml){ pointsText = document.getElementById('edit-'+this.prefix+'-points').value; gmapBaseController.prototype.xmlToPoints.call(this, pointsText, true); } gmapAdminController.prototype.serializeAll = function(){ this.serializeMap(); this.serializeMapPoints(); }; gmapAdminController.prototype.serializeMap = function(){ document.getElementById('edit-'+this.prefix+'-mapzoom').value = this.map.getZoom(); document.getElementById('edit-'+this.prefix+'-maplon').value = this.map.getCenter().x; document.getElementById('edit-'+this.prefix+'-maplat').value = this.map.getCenter().y; switch(this.map.getCurrentMapType()){ case G_NORMAL_MAP: document.getElementById('edit-'+this.prefix+'-maptype').value = 'G_NORMAL_MAP'; break; case G_SATELLITE_MAP: document.getElementById('edit-'+this.prefix+'-maptype').value = 'G_SATELLITE_MAP'; break; case G_HYBRID_MAP: document.getElementById('edit-'+this.prefix+'-maptype').value = 'G_HYBRID_MAP'; break; default: break; } }; gmapAdminController.prototype.serializeMapPoints = function(){ document.getElementById(this.prefix+'markers').innerHTML = this.pointsToInputs(); }; gmapAdminController.prototype.pointsToInputs = function(){ //create a string for the name field. ns = this.prefix.replace('-', '_', 'g'); inputs = ''; for(var i=0;i"; inputs += ""; if(this.markerList[i].title) inputs += ""; if(this.markerList[i].description) inputs += ""; if(this.markerList[i].image) inputs += ""; } document.getElementById('edit-'+ this.prefix + '-itemcount').value = this.markerList.length; return inputs; } gmapAdminController.prototype.initializePoints = function () { numPoints = parseInt(document.getElementById('edit-'+ this.prefix + '-itemcount').value); for(var i=0;i 0){ return img.value; } } return null; } gmapAdminController.prototype.updateMarkerImage = function(){ var imgsrc = document.getElementById('edit-'+this.prefix+'-markerImage').value; var img = ""; document.getElementById(this.prefix+'current_map_image').innerHTML=img; }