Google Maps
Google Maps
The Google Maps shortcode embeds an interactive map using the Google Maps JavaScript API. Add the class gmap to any container, size it with utility classes, and configure the location, zoom, markers, and custom styles through data-* attributes. An API key is required.
API key requirement
The map will not render without a Google Maps API key. Set gmapAPI in js/functions.bundle.js (or via cnvsOptions). If the key is missing, Canvas replaces the map area with a warning notice instead of failing silently.
Basic map by address
The simplest setup uses data-address. The plugin geocodes the address and drops a marker there.
<div class="gmap h-100" data-address="Melbourne, Australia" data-zoom="14"></div>Size the container yourself, for example with h-100, vh-40, or a fixed height, since an empty map has no intrinsic height.
Map by coordinates
Use data-latitude and data-longitude for precise placement.
<div class="gmap vh-40"
data-latitude="41.8333925"
data-longitude="-88.0121473"
data-zoom="12"></div>Key attributes
- data-address: a text address to geocode and mark. Takes priority over latitude/longitude.
- data-latitude / data-longitude: exact coordinates (used when no address is given).
- data-zoom: zoom level. Default
12. - data-maptype:
ROADMAP(default),SATELLITE,HYBRID, orTERRAIN. - data-scrollwheel: set to
falseto disable zoom on mouse-wheel scroll. - data-content: HTML for the marker info window when using a single address/coordinate.
- data-markers: a JSON array of marker objects for multiple markers.
- data-icon: a JSON object describing a custom marker image.
- data-styles: a JSON array of Google Maps style rules for custom map colors.
- data-control-pan, data-control-zoom, data-control-maptype, data-control-scale, data-control-streetview, data-control-overview: set to
trueto show the matching map control (all off by default).
Multiple markers with custom icon
<div class="gmap h-100"
data-address="Melbourne, Australia"
data-markers='[{address: "Melbourne, Australia", html: "<div class=\"p-2\" style=\"width: 300px;\"><h4 class=\"mb-2\">Hi! We are Envato!</h4><p class=\"mb-0\">We operate marketplaces where people buy and sell digital goods.</p></div>", icon:{ image: "images/icons/map-icon-red.png", iconsize: [32, 39], iconanchor: [32,39] } }]'></div>Styled (custom colored) map
Pass a data-styles JSON array. This example lightens water, landscape, and roads for a soft, muted look.
<div class="gmap h-100"
data-address="Melbourne, Australia"
data-scrollwheel="false"
data-styles='[{"featureType":"water","elementType":"geometry","stylers":[{"color":"#e9e9e9"},{"lightness":17}]},{"featureType":"landscape","elementType":"geometry","stylers":[{"color":"#f5f5f5"},{"lightness":20}]},{"featureType":"road.highway","elementType":"geometry.fill","stylers":[{"color":"#ffffff"},{"lightness":17}]}]'></div>Full-bleed background map
Position the map absolutely behind other content, useful for page titles and contact sections.
<div class="gmap-bg gmap h-100 position-absolute top-0 start-0 w-100 z-1"
data-address="Melbourne, Australia"
data-scrollwheel="false"></div>Tips
- Prefer valid JSON for
data-markers,data-styles, anddata-icon. The plugin will warn if it has to fall back to loose JS-literal parsing. - Always give the
.gmapelement a height, or the map will collapse to zero pixels. - Use
data-scrollwheel="false"on maps embedded inside scrollable pages so the wheel scrolls the page, not the map. - Generate custom
data-stylesvisually with a Google Maps styling tool, then paste the JSON array.
Usage
<div class="gmap" style="height: 250px;" data-address="Melbourne, Australia" data-zoom="12" data-markers='[{address: "Melbourne, Australia",html: "Melbourne, Australia"}]' data-icon='{image: "one-page/images/icons/map-icon-red.png",iconsize: [32, 32],iconanchor: [14,44]}'></div>How to Use
- 1
Add API Key
Add your API Key in the
js/functions.jsFile. Find:gmapAPI: '',and Add your API Key within the Single Quotes (Do not delete the Quotes). You can generate your API Key for Google Maps by Clicking Here. Make sure that you have already Restricted for your API Key including an HTTP Referrer and API Restrictions to avoid any unauthorized use.
- 2
Use this HTML Code
<div class="gmap" style="height: 250px;" data-address="Melbourne, Australia" data-zoom="12" data-markers='[{address: "Melbourne, Australia",html: "Melbourne, Australia"}]' data-icon='{image: "one-page/images/icons/map-icon-red.png",iconsize: [32, 32],iconanchor: [14,44]}'></div>
Settings
| Setting | Description |
|---|---|
data-latitude | Latitude for your Map Location This will be ignored if you add a Value for data-address |
data-longitude | Longitude for your Map Location This will be ignored if you add a Value for data-address |
data-address | Address of your Map Location Example: Melbourne, Australia |
data-content | Content of the Marker Popup of the Default Address Make sure that you escape Double Quotes and use Single Quotes where necessary |
data-zoom | Set the Default Zoom for your Map Example: 12 |
data-maptype | Set the Default MapType for your Map Example: TERRAIN |
data-scrollwheel | Enable/Disable Scrollwheel Zoom In/Out for your Map Example: true |
data-styles | Set a Custom Style for your Map. You can create your own Style or Choose from the Snazzy Maps Library. Make sure that you Trim and Minify the Styles Codes before using to avoid line-break issues (Use this tool and remove Space, Tabs and Lines). Example: [{"featureType":"all","elementType":"all","stylers":[{"saturation":"32"},{"lightness":"-3"},{"visibility":"on"},{"weight":"1.18"}]},{"featureType":"administrative","elementType":"labels","stylers":[{"visibility":"off"}]},{"featureType":"landscape","elementType":"labels","stylers":[{"visibility":"off"}]},{"featureType":"landscape.man_made","elementType":"all","stylers":[{"saturation":"-70"},{"lightness":"14"}]},{"featureType":"poi","elementType":"labels","stylers":[{"visibility":"off"}]},{"featureType":"road","elementType":"labels","stylers":[{"visibility":"off"}]},{"featureType":"transit","elementType":"labels","stylers":[{"visibility":"off"}]},{"featureType":"water","elementType":"all","stylers":[{"saturation":"100"},{"lightness":"-14"}]},{"featureType":"water","elementType":"labels","stylers":[{"visibility":"off"},{"lightness":"12"}]}]Make sure that you escape Double Quotes and use Single Quotes where necessary |
data-control-pan | Enable/Disable Pan Control for your Map |
data-control-zoom | Enable/Disable Zoom Control for your Map |
data-control-maptype | Enable/Disable MapType Control for your Map |
data-control-scale | Enable/Disable Scale Control for your Map |
data-control-streetview | Enable/Disable StreetView Control for your Map |
data-control-overview | Enable/Disable Overview Control for your Map |
data-markers | Add Markers to your Map Example: data-markers='[{address: "Melbourne, Australia",html: "Melbourne, Australia"},{address: "Sydney, Australia",html: "Sydney, Australia"}]' |
Screenshots







Extras
Markers with Different Icons
Canvas Google Maps reads all marker data from data-* attributes on the .gmap element. To give each marker its own icon, pass a JSON array via data-markers and override the default icon per marker with an icon object.
First set your API key in js/functions.bundle.js (the gmapAPI option), then:
<div class="gmap" style="height:450px"
data-maptype="ROADMAP"
data-zoom="13"
data-scrollwheel="false"
data-markers='[
{ "latitude": 40.7143528, "longitude": -74.0059731, "html": "Main Office",
"icon": { "image": "images/icons/marker-red.png", "iconsize": [32, 37], "iconanchor": [16, 37] } },
{ "latitude": 40.7043528, "longitude": -74.0159731, "html": "Warehouse",
"icon": { "image": "images/icons/marker-blue.png", "iconsize": [32, 37], "iconanchor": [16, 37] } }
]'>
</div>Notes:
- The default map icon (used when a marker has no
icon) is set globally throughdata-icon. Per marker, put theiconobject inside each item of thedata-markersarray. - Icon keys the plugin understands:
image,shadow,iconsize,shadowsize,iconanchor,shadowanchor(each size/anchor is a[width, height]pair). data-markersmust be valid JSON. The parser warns in the console if it has to fall back to loose evaluation, so keep it strict JSON for CSP safety.- You can also point a marker at a street address with
"address": "..."instead of latitude/longitude.
