Smart Map

Documentation  •  Changelog


KML files

When the needs of your map get too complex, you may find it beneficial to create a custom map with Google My Maps (or a similar service). Once you have your KML file in hand, there are two ways to apply it using Smart Map...

Generate a new map from the KML file

You can use the kml function to generate a new map from scratch, simply pass in the KML asset and options. The options are identical to the list of standard map options.

kml(kmlFile, options)


{% set kmlFile = entry.kmlFile.one() %}
{% set options = {
    height: 400,
    center: {'lat':34.0522342, 'lng':-118.2436849}
} %}

{% if kmlFile %}
    {{ craft.smartMap.kml(kmlFile, options) }}
{% endif %}

Apply the KML file to an existing map

If you'd like to apply the KML file to an existing map, use kmlLayer. You can pass in the KML file, and the map ID of your target map.

kmlLayer(kmlFile, mapId)


{% set kmlFile = entry.kmlFile.one() %}

{% if kmlFile %}
    {{ craft.smartMap.kmlLayer(kmlFile, 'smartmap-mapcanvas-1') }}
{% endif %}

The KML file must be publicly accessible

Because of the way Google Maps applies the KML layer, the KML file must be accessible from a public website.

If you are testing this feature locally, the KML file may refuse to load.