-
Notifications
You must be signed in to change notification settings - Fork 19
Template Reference
It's important to realize that the majority of the these tags are merely generating JavaScript and adding it to the DOM. If additional customization is required that is outside the scope of these tags, you can always interact with your maps directly using JavaScript.
- Center
- Current Location
- Data
- Geocode
- Map
- Map Data Model
- Marker
- Polygon
- Polyline
- Route
- Static Map
- Zoom
craft.googleMaps.center allows you to center a map with a template tag after it has been initialized. The tag is polymorphic in that is allows you to pass a coordinate or an address string. If an address string is passed, the string is geocoded and the first returned result will be used to center the map.
craft.googleMaps.center('yourMapId', 40, -86)
craft.googleMaps.center('yourMapId', 'Miami, Florida')
- id - Your map's id
- lat - The lat coordinate or address string
- lng - The lng coordinate (if not passing an address string)
craft.googleMaps.currentLocation allows you to use the HTML5 Geolocation API to plot the user's current location on the map. You have full control over the icon, but the default will work fine with no options set. The markerOptions property should be Marker Options from Google Maps. The circleOptions property should be Circle Options from Google Maps.
{{ craft.googleMaps.currentLocation('map') }}
- id - Your map's id
- options - And object to various options
{
// Extend the bounds of the map to include this marker?
fitBounds: true,
// Additional marker options to be used provided by the
// Google Maps API
markerOptions: {},
// Additional circle options to be used provided by the
// Google Maps API
circleOptions: {}
}
craft.googleMaps.data will add your field type data to an instantiated Google Map. This tag will handle adding all the map data you have saved to the map.
craft.googleMaps.data('yourMapId', entry.yourMapField)
- id - Your map's id
-
data - A valid
GoogleMaps_MapDataModel
craft.googleMaps.geocode allows you to geocode data using the server-side geocoder (vs. using a client-side geocoder with JavaScript). You can use this data to loop through it and output whatever you need in your template. A Geocode Response Object will be returned.
{% set response = craft.googleMaps.geocode('Texas') %}
{% if response.status == 'OK' %}
{% for result in response.results %}
<p>{{ result.geometry.location.lat}} {{ result.geometry.location.lng}}</p>
{% endfor %}
{% endif %}
- address - An address string to geocode
craft.googleMaps.map will generate a JavaScript map in the DOM automatically. The map tag accepts all the native map options in addition to a few provided by the plugin.
{% set options = {
id: 'yourMapId',
width: '400px',
height: '300px',
someMapParamHere: 'some value',
} %}
{{ craft.googleMaps.map(options) }}
-
id - An valid JavaScript variable name which will be used as a global variable to store the
GoogleMaps.Mapobject. - width - The map's width. Can be pixel or percentage, but must be passed as a string.
- height - The map's height. Can be pixel or percentage, but must be passed as a string.
craft.googleMaps.mapDataModel will accept data in the form of an object and use it to instantiate a GoogleMaps_MapDataModel object. This tag is useful to generate your own models that can be used in other tags that require these models passed as parameters.
{% set mapData = craft.googleMaps.mapDataModel({
markers: [{
title: 'Texas',
address: 'Texas'
},{
title: 'Florida',
address: 'Florida'
},{
title: 'Some Random Place',
lat: 67.510245,
lng: -86.021041
}]
})
%}
-
data - The data object used to instantiate a
GoogleMaps_MapDataModelobject.
craft.googleMaps.marker will add a new marker to an instantiated map. In addition to the native parameters, you can pass all the supported marker options provided by the Google Maps API.
`craft.googleMaps.marker('yourMapId', {address: 'Some Address', options: {someOption: 'some value'}});
- id - Your map's id
-
data - The data object used to instantiate a
GoogleMaps.Markerobject.
{
// The marker's infowindow content
content: false,
// The marker's latitude (if applicable)
latitude: false,
// The marker's longitude (if applicable)
longitude: false,
// The marker's address (if applicable)
address: false,
// close existing infowindows when the infowindow is triggered
closeInfoWindows: true,
// The trigger to open an infowindow (default is click)
infoWindowTrigger: 'click',
// Open the infowindow when the infowindow event is triggered?
openInfoWindowOnTrigger: true,
// Extend the bounds of the map to include this marker?
fitBounds: true,
// Additional marker options to be used provided by the
// Google Maps API
options: {}
}
craft.googleMaps.polygon allows you to add polygons to an instantiated map. All the polygon options are supported by the Google Maps API.
{{ craft.googleMaps.polygon('map', [[0, 0], [0, 10], [10, 10], [10, 0]], {options: {strokeColor: 'red'}}) }}
- id - Your map's id
- coords - An array of coordinates to be used a points in the polygon
-
data - The data object used to instantiate a
GoogleMaps.Polygonobject.
{
// Extend the bounds of the map to include this marker?
fitBounds: true,
// Additional polygon options to be used provided by the
// Google Maps API
options: {}
}
craft.googleMaps.polyline allows you to add polylines to an instantiated map. All the polyline options are supported by the Google Maps API.
{{ craft.googleMaps.polyline('map', [[0, 0], [0, 10], [10, 10], [10, 0]], {options: {strokeColor: 'red'}}) }}
- id - Your map's id
- coords - An array of coordinates to be used a points in the polygon
-
data - The data object used to instantiate a
GoogleMaps.Polygonobject.
{
// Extend the bounds of the map to include this marker?
fitBounds: true,
// Additional polygon options to be used provided by the
// Google Maps API
options: {}
}
craft.googleMaps.staticMap will generate a static map in the template. The map will be cached in the craft/storage/googlemaps/static directory, and then the cached map will be used to avoid subsequent requests to the API (thus dramatically speeding up page load times).
{{ craft.googleMaps.staticMap(entry.map, {width: 300, height: 200}) }}
-
data - This must be an instance of
GoogleMaps_MapDataModelorGoogleMaps_StaticMapModel - options - The data object used to generate the map. These values come directory from the Static Maps API
{
// The map's center coordinate. By default, the center
// is automatically calculated based on the markers on
// the map
center: false,
// The image format that is returned (png|jped|gif)
format: 'png',
// The maptype that is used (roadmap|satellite|terrain|hybrid)
maptype: 'roadmap',
// An array of GoogleMaps_MarkerModel objects
markers: [],
// The map's scale (1|2)
scale: 1,
// The map's custom style options
style: false,
// The map's zoom level. Zoom is automatically calculated
// based on the markers on the map.
zoom: false
}
craft.googleMaps.zoom will dynamically zoom the map to a defined value.
craft.googleMaps.zoom('yourMapId', 12)
- id - The maps' id
- level The zoom level (1-20)