Modules / Maps

Map: sync markers with a query loop

Map (Leaflet): sync with a query loop

Bricks offers "Sync with query" on its Google map only. This module adds it to the Map (Leaflet) element. The markers come from the Map Connector elements inside a query loop and follow the loop's filters and pagination. As on the Google map, you can cluster the markers, show the connector's active marker while its item is hovered, and style the popups.

  • On by default
  • Needs Bricks 2.4 or newer
  • Tested with Bricks 2.4.3
Recording: someone points a Leaflet map at the Stockists loop; on the live page the map fits all five shops, and ticking West narrows both the list and the map to Calgary and Victoria.Recorded in Bricks 2.4.3

How to use it

  1. Build a query loop on the page.
  2. Inside the loop, add Bricks' Map Connector element. Give it a latitude and a longitude. A marker image and an Info Box popup template are optional.
  3. Select the Map (Leaflet) element. In its Markers controls, find the separator Sync with query (Kiln).
  4. In the query list under it, choose your loop (Select query loop). The page's main query is not offered.
  5. Optional, once a loop is chosen:
    • Keep the map's center and zoom (do not fit to the markers), or Keep the markers above as well;
    • Fit padding (px), 40 by default, and Max zoom when fitting, so a few close markers don't zoom the map in to street level;
    • Marker click scrolls to its loop item;
    • Cluster markers, then Cluster background color, Cluster text color, Cluster size (px) (40 by default) and Cluster distance (px), how close markers must be on screen to join a cluster (60 by default).
  6. To style the popups, open the Style tab and Popup (Kiln): Background color, Border radius, Box shadow, Padding, Typography and Close button color.
  7. View the page on the front end.

Where it appears in Bricks

On the Map (Leaflet) element, in the Markers controls, and Popup (Kiln) in its Style tab. The controls show in the builder, but the synced markers show on the front end only. In the builder, the map keeps the markers you set on the element. The popup styles apply to every marker on the map, synced or not.

What the map does

  • It fits the view to the loop's markers, with 40 pixels of padding unless you set another. With one marker, or markers at the same spot, it centres on that point and keeps the current zoom, or the max zoom if that is lower.
  • It updates after query filters, AJAX pagination and "load more".
  • A marker uses the Map Connector's marker image at 40 pixels tall, with the image's own proportions. Without an image, the marker is Leaflet's default.
  • The marker's popup is the Info Box template, when the connector has one. Without a template, the popup is the marker's label as plain text.
  • A map hidden at load, for example in a tab, an accordion or a popup, fits its markers when it is revealed.
  • Hovering a loop item adds the class kiln-map-active to its marker, and hovering a marker adds it to its loop item. Keyboard focus on the item does the same. Kiln styles the class only on a cluster (an outline); for markers and items, add your own CSS.
  • When the connector has an active marker image, hovering or focusing the loop item shows that image on the marker, as Bricks' Google map does. Hovering the marker itself keeps its image.
  • With clustering on, markers close together become a circle with their count. A click on it zooms in until they split. Hovering a loop item whose marker is inside a cluster highlights the cluster. The clusters don't animate when the visitor's system asks for reduced motion.
  • With Marker click scrolls to its loop item, a click on a marker also scrolls the page so its item is in the middle of the screen. It jumps instead of gliding when the visitor's system asks for reduced motion.
  • A connector with a missing latitude or longitude, or a value outside the valid range, is skipped.
  • If the chosen loop is not on the page, the map keeps its own markers.

How it works with the markers on the element

By default, Kiln removes the markers set on the Map (Leaflet) element once the sync starts. Tick Keep the markers above as well to keep them. They then count toward the fit.

Limits

  • Latitude and longitude only. Kiln doesn't geocode the connector's address field, because Leaflet has no geocoder.
  • Kiln can't use an Info Box template set to load by AJAX. The marker's label shows instead.
  • Synced markers show on the front end only. The builder shows the markers set on the element.
  • Clustering, the active marker, the fit options and the marker click apply to synced markers. Kiln doesn't cluster the markers set on the element.
  • Clustering loads Leaflet.markercluster 1.5.3 (MIT licence), about 34 KB, from the plugin. It loads only on pages with a clustered map.

Settings

None. The module is on by default and does nothing until you choose a loop on a map.

Requirements

Bricks 2.4 or newer.