- 🇩🇰Denmark ressa Copenhagen
Thanks for sharing your solution @gl2748. I am interested in defining setMaxBounds in Drupal 10, to restrict the map view to the given bounds, and hope it's ok I re-open your issue, instead of creating a new one.
Is a custom module the recommended solution, or is it possible to define via one of the fields in the Views Leaflet Map Format Settings pop up form?
- Status changed to Fixed
over 1 year ago 8:59pm 2 July 2023 - 🇮🇹Italy itamair
Well ... pretty easy, considering that once each Leaflet Map is initialised it triggers the 'leafletMapInit' event (https://git.drupalcode.org/project/leaflet/-/blob/10.0.x/js/leaflet.drup...)
you can create your own js library / interactions with the following Drupal.behavior and code (that should be loaded before the leaflet.drupal.js file):(function ($, Drupal) { Drupal.behaviors.customLeafletInteraction = { attach: function (context, settings) { // React on leafletMapInit event. $(context).on('leafletMapInit', function (e, settings, lMap, mapid, markers) { // Do whatever you want the specific Leaflet map object (lMap), also apply the setMaxBounds method ... } ...
- 🇩🇰Denmark ressa Copenhagen
Beautiful @itamair, that was easy, but only thanks to you kindly adding the missing piece of the puzzle. Thank you so much for a fast and very helpful answer.
I noticed that there wasn't a Leaflet documentation page for Drupal 10, so I created a Leaflet guide and a Leaflet API page, documenting how to add the JS file with a working
setMaxBounds
method example:- /docs/extending-drupal/contributed-modules/contributed-module-documentation/leaflet →
- /docs/extending-drupal/contributed-modules/contributed-module-documentation/leaflet/leaflet-ap →
Maybe over time, the relevant info from the Drupal 7 Leaflet doc page → can be updated and transfered to the Drupal 10 Leaflet docs page?
The page is ready now, at least.
- Status changed to Needs review
over 1 year ago 11:17am 3 July 2023 - 🇩🇰Denmark ressa Copenhagen
Maybe you can check the new Drupal 10 doc pages and see if they make sense, or anything needs to be updated?
- Status changed to Fixed
over 1 year ago 8:32pm 3 July 2023 Automatically closed - issue fixed for 2 weeks with no activity.