Ext.ns('S100'); S100.MapMarker = function(data, type) { this.data = data; this.type = type; this.isActive = false; this.addEvents({ 'markerclick' : true }); this.init(); this.setupEvents(); }; Ext.extend(S100.MapMarker, Ext.util.Observable); S100.MapMarker.MARKER_IMAGE = '/images/markers.png'; S100.MapMarker.SHADOW_IMAGE = '/images/marker_shadow.png'; S100.MapMarker.PLACE_POINT = {x:0, y:0}; S100.MapMarker.PLACE_POINT_ACTIVE = {x:32, y:0}; S100.MapMarker.PERSON_POINT = {x:0, y:43}; S100.MapMarker.PERSON_POINT_ACTIVE = {x:32, y:43}; S100.MapMarker.COMMUNITYPERSON_POINT = {x:0, y:84}; S100.MapMarker.COMMUNITYPERSON_POINT_ACTIVE = {x:32, y:84}; S100.MapMarker.COMMUNITYPLACE_POINT = {x:0, y:129}; S100.MapMarker.COMMUNITYPLACE_POINT_ACTIVE = {x:32, y:129}; S100.MapMarker.prototype.init = function() { this.setupMarkerDefaults(); this.createMarker(); }; S100.MapMarker.prototype.setupEvents = function() { google.maps.event.addListener(this.getMarker(), 'click', this.onMarkerClick.createDelegate(this)); }; S100.MapMarker.prototype.onMarkerClick = function(evt) { this.fireEvent('markerclick', {marker: this}); this.toggleState(true); }; S100.MapMarker.prototype.createMarker = function() { this.googleMarker = new google.maps.Marker({ icon: this.getImage(), shadow: this.getShadow(), position: this.positionLatLng, title: this.data.name }); }; S100.MapMarker.prototype.setupMarkerDefaults = function() { var latlngParts = this.data.address_lat_long.split(',') this.positionLatLng = new google.maps.LatLng(latlngParts[0], latlngParts[1]) // Marker size this.size = new google.maps.Size(29,43); // Position to marker in sprite this.point = S100.MapMarker[this.type.toUpperCase() +'_POINT']; this.activePoint = S100.MapMarker[this.type.toUpperCase() +'_POINT_ACTIVE']; // Shadow position this.shadowSize = new google.maps.Size(45,27), this.shadowAnchor = {x: 7, y: this.shadowSize.height-2}; }; S100.MapMarker.prototype.toggleState = function(active) { this.isActive = active; this.getMarker().setIcon(this.getImage(active)); }; S100.MapMarker.prototype.getImage = function(active) { var point = active ? this.activePoint : this.point; return new google.maps.MarkerImage(S100.MapMarker.MARKER_IMAGE, this.size, point); }; S100.MapMarker.prototype.getShadow = function() { return new google.maps.MarkerImage(S100.MapMarker.SHADOW_IMAGE, this.shadowSize, {x:0,y:0}, this.shadowAnchor); }; S100.MapMarker.prototype.getMarker = function() { return this.googleMarker; }; S100.MapMarker.prototype.getData = function() { return this.data; }; S100.MapMarker.prototype.getType = function() { return this.type; };