Skip to content

Instantly share code, notes, and snippets.

@RSpace
Created December 11, 2010 22:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RSpace/737706 to your computer and use it in GitHub Desktop.
Save RSpace/737706 to your computer and use it in GitHub Desktop.
function Location(id, data) {
// Public variables
this.id = id;
this.latitude = data["location"]["latitude"];
this.longitude = data["location"]["longitude"];
this.postal_district_id = data["location"]["postal_district_id"];
this.area_from = data["location"]["area_from"];
this.area_to =
...
};
// This class manages everything related to the locations map
// This example does not include the full code
function MapManager(location_manager) {
this.location_manager = location_manager;
this.locations = location_manager.locations;
this.markers = [];
this.skip_clear = location_manager.skip_clear;
// Subscribe to events
var map_manager = this;
$(document).bind("table.markerClicked", function(e, location) { location.getMapMarker().openInfoWindowHtml(map_manager.getInfoWindowHtml(location)); });
$(document).bind("table.rowMouseOver", function(e, location) { map_manager.highlightMarker(location); });
$(document).bind("table.rowMouseOut", function(e, location) { map_manager.resetHighlight(location); });
$(document).bind("postal_districts.filterChanged", function(e) { map_manager.updateMap(false); map_manager.centerAndZoomOnMarkers(); });
$(document).bind("size.filterChanged", function(e) { map_manager.updateMap(false); map_manager.centerAndZoomOnMarkers(); });
$(document).bind("price.filterChanged", function(e) { map_manager.updateMap(false); map_manager.centerAndZoomOnMarkers(); });
// "Constructor"
this.setupLocationsMap = function() {
this.addMarkersToMap();
};
this.markerClicked = function(location) {
location.getMapMarker().openInfoWindowHtml(this.getInfoWindowHtml(location));
$(document).trigger('map.markerClicked',[location]);
};
this.markerMouseOver = function(location) {
this.highlightMarker(location);
$(document).trigger('map.markerMouseOver',[location]);
};
this.markerMouseOut = function(location) {
this.resetHighlight(location);
$(document).trigger('map.markerMouseOut',[location]);
};
// Adds a single marker to the map
this.addMarker = function(marker) {
this.markers.push(marker);
this.map().addOverlay(marker);
};
// Adds a location to the map
this.addLocationToMap = function(location) {
// Build the marker
marker = new GMarker( ... );
// Hook up events
var map_manager = this;
GEvent.addListener(marker, 'click', function(coordinates) { map_manager.markerClicked(location); });
GEvent.addListener(marker, 'mouseover', function(coordinates) { map_manager.markerMouseOver(location); });
GEvent.addListener(marker, 'mouseout', function(coordinates) { map_manager.markerMouseOut(location); });
// Add it to the map
this.addMarker(marker);
};
...
// Constructor "calls"
this.setupLocationsMap();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment