var_plugIn=this,// Reference back to the "mapsed" plug-in instance
_searchBox=null,// Search box that appears on the map
_gmSearchBox=null,// Google (autocompleting) Search box the underlying input text box is twinned with
_searchBtn=null,// Button to click to confirm search should be applied (not strictly needed (ENTER does the same), but users may be confused if there isn't one!)
_moreBtn=null,// Available when more results are available for a result set (Google Places API pages the results)
_pageNum=0,// Keeps track of how many pages of results are shown (used to reset the markers on a new search)
_gMap=null,// Underlying Google maps object for the div
_mapContainer=null,// jQuery reference to the DIV the map is in
_placesApi=null,// Reference to the Google Places API object
_markers=[],// Set of markers displayed on the map
_instance=-1,// Instance "this" plug-in is managing (so we can support zmultiple maps on the page)
_fullWin=false,// Flags "mapsed" is in full-window mode, which means "mapsed" created the DIV we're in
_firstSearch=true,// Used to ensure we don't clear markers when the map is drawn for the first time (so any "showOnLoad" markers aren't cleared)
_hasMapInitFired=false,// Used to flag initialisation of the map (after Google Maps API has finished drawing it)
_areBoundsSet=false,// Used to flag that an event has set the boundary (so we don't set the zoom/center manually as GM will calc this for us)
_helpBtn=null,// Reference to the help dialog button ([?])
_helpDlg=null,// Reference to the help dialog that is toggled by the help button
_closeBtn=null,// Reference to the close button (only used in full-window mode)
_addBtn=null,// Reference to the add button ([+])
_geoBtn=null,// Reference to the Geo location button [(*)]
gm=null,// Short cut reference to the Google Maps namespace (this is initialised in the constructor to give the Google API time to load on the page)
gp=null// Short cut reference to the Google Places namespace (this is initialised in the constructor to give the Google API time to load on the page)
;
/// <summary>
/// Plug-in options:
/// Set of options to configure how the map will behave
/// </summary>
varsettings=$.extend({
// Array of places to show on the map initially
// (see accompanying examples for illustration)
showOnLoad:null,
// Specifies the buttons and tooltips added to the map toolbar
ToolbarButtons:{
Go:"Go",
More:"More|There are more results available ...",
AddPlace:"+|Add a place",
CloseMap:"×|Close map",
Geo:"⊗|Centre map based on your location",
Help:"?|Show help"
},
// Species the text of the buttons used the dialog templates
ActionButtons:{
Select:"Select",
Edit:"Edit",
Delete:"Delete",
Save:"Save"
},
// Options for drawing the map. This is the same object
// that is passed to the Google Maps API when creating the map.
// If you need something custom supported by the Google Maps API
// you should be able to add in your own initialisation code
// to this object.
mapOptions:{
// Initial zoom level (initially not set)
// ... be cautious when setting a zoom level _and_ defining custom places as you may set the
// ... level to such a level that your places aren't visible
// ... by default the map will expand to show all custom places, you can change this with the "forceCenter" option
zoom:DEFAULT_ZOOM,
// Default to the best theatre ever :-)
center:DEFAULT_CENTER,
// Type of map to show initially
mapTypeId:google.maps.MapTypeId.ROADMAP
},
// Flags whether Google Maps should still display other points-of-interest
// By default POI is enabled because the POIs can't be turned off when using custom styled maps
// (well without significant hacks!)
// If you require custom maps, you need "disablePoi" set to false
disablePoi:false,
// Flags that the user can add new places (as well as edit/delete), an "+" icon appears
// at the top right of the map
allowAdd:false,
searchOptions:{
// Flags that the user can search for places themselves
// ... adds a search box to the map
enabled:false,
// Placeholder text for the search box
placeholder:"e.g. Hotels in Leeds",
// Initialises the place search with a given text search
// ... (i.e. once the map has been created, the results for this string are also shown)
initSearch:"Hotels in Leeds",
// Performs a search when geo-location is activated. This can be either
// on load (see "findGeoOnLoad" option) or when the Geo location button is clicked
// {POSITION} is replaced with the detected Geo location position
// "geoSearch" supersedes any "initSearch" specified (if the user enables Geo location for the map)
geoSearch:"5aside football near {POSITION}"
},
// Event when user clicks the "Select" button
// prototype: function(mapsed, details)
onSelect:null,
// Allows new places to be edited
// prototype: function(mapsed, newPlace)
// return a error message string if you're not happy with what's been entered
// return an empty string to confirm it's been saved
onSave:null,
// Allows the user to delete a "custom" map they've previously added
// prototype: function(mapsed, details)
// return true to confirm delete, false abandons the delete
onDelete:null,
// Flags that the user is asked for confirmation if they try and
// delete a place
confirmDelete:false,
// Event fires when user clicks the "X" button (only in full window mode)
// prototype: function(mapsed)
// return true to close the map, false keeps it open
onClose:null,
// Callback for getting the [image] URL to use for a marker
// Parameter "markerType" is passed, indicating the type of marker, this can be
// prototype: function(mapsed, markerType, title)
// Parameters:
// mapsed: Reference to the mapsed plugin
// markerType: The type of marker being added to the map:
// "new" = Marker created using the "+" button to add a new place
// "google" = Marker is being added from a Google Places place
// "custom" = Marker is being added from application database (via "showOnLoad" array)
// title: Title attribute of the marker
// Returns:
// Google Icon object (see https://developers.google.com/maps/documentation/javascript/reference#Icon)
getMarkerImage:null,
// Adds a help button to give further instructions to the end user
// prototype: function()
getHelpWindow:null,
// show the help dialog when the map is loaded
showHelpOnLoad:false,
// Adds a GEO location button onto the map which is used to set the
// centre of the map according to the user's GEO location position
allowGeo:false,
// Flags that mapsed should place the centre of the map where the user's
// GEO location position is.
// Note: This is ignored if "showOnLoad" property is populated as there is
// a risk the places won't be shown on the map
findGeoOnLoad:false,
// When adding custom places, mapsed will expand the map to show all places
// Usually this is what you'd want, but sometimes you may want to focus on a particular area
// "forceCenter" will override the default behaviour and centre where specified in the options
forceCenter:false
},options||{});
//
// PUBLIC METHODS
//
/// <summary>
/// Get the settings the map was build with
/// </summary>
this.getSettings=function(){
returnsettings;
};
/// <summary>
/// Gets the underlying Google Map object that was initially
/// created
/// - useful if you want to play directly with the map to provide
/// further functionality outside mapsed
/// </summary>
this.getGoogleMap=function(){
return_gMap;
};
/// <summary>
/// Usually you'll already know this (it's how you called up
/// the mapsed jQuery plugin - however in full-window mode the div is
/// generated, so you'll need this then ... sometimes :-)
/// - see "onPreInit" full-window example.
/// </summary>
this.getMapContainer=function(){
return_mapContainer;
};
/// <summary>
/// Helper method to make it a bit easier to add your own controls onto
/// the map.
/// markUp - HTML for the control (just HTML, no jQuery or anything, ID is _not_ required)
/// ctrlPos - Where on the map the control should be added, available options details here: