Embed JS
Last updated
Last updated
Boldmapper's Embed
JavaScript module allows you to add (or embed) maps to a web page. The following is a guide of the module's usage and features.
The following assumes you have a map with an ID of abcd-1234-defg-5678-hijk
. To embed this map on a webpage, you can do the following:
Add an element to the page's HTML where you want the map to appear:
Add a script to the page's <head>
or just before the closing </body>
tag to initialize and mount the embed:
The above script imports the Embed
module, creates a new embed instance with the given map ID, and mounts it on the target element. The result is a Boldmapper map being rendered at the target element when the page is loaded.
The Embed instance can take the following parameters when being initialized:
Option | Description | Default |
---|---|---|
Embed instances have the following methods available to them:
Mounts the embed to the specified element. The argument can be either a DOM element or a CSS selector string (the first matching element will be used).
Removes the embed from the page, restoring the mount element to it's pre-mount state. This can be useful when an explicit teardown is required (e.g. when rendering maps on pages with non-standard navigation handling, like Single Page Apps or Turbolinks).
mapId
Required. The ID of the map you wish to render. This should be a UUID string and can be found on your map's Settings page.
N/A
onLoad
A callback function that is triggered when the embed and its map container are loaded.
null
onLocationSelect
A callback function that is triggered when a location is selected, either by click or via a search result. The callback function can take a "location" argument which contains some information about the selected location (e.g. name, address).
null