Adding GeoJson resource into a Drupal Leaflet Map View

Created on 19 August 2023, over 1 year ago
Updated 19 December 2023, 11 months ago

Drupal Leaflet module supports adding GeoJson resources according with official "Using GeoJSON with Leaflet" guide.

The correct approach entails the use of a Drupal Behaviour reacting on leafletMapInit event, originally triggered right after loading the Leaflet Map (and defined at the end of the loadMap method from here) ...

For more detailed information and guide on this, please refer to the following Leaflet Map GeoJson Demo page, and related instructions / insights ...

💬 Support request
Status

Closed: outdated

Version

10.0

Component

Documentation

Created by

🇮🇹Italy itamair

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @itamair
  • 🇫🇷France b2f

    That doesn't sound great since a Drupal architecture is first resolving around php classes such as controllers, forcing to do those declarations in JS behaviors is adding a significant overhead to go back & forth between JS and php, although before d10 update it was perfectly fine.

    Especially if the json data is held into entity fields and multiple maps are managed around a factored map structure.

  • 🇮🇹Italy itamair

    Well ... @b2f what you say is not correct IMHO, as this approach is exactly matching the one that the Leaflet Map library is guiding to: https://leafletjs.com/examples/geojson/

    L.geoJSON(geojsonFeature).addTo(map);

    (and of course Leaflet JS library is not expecting any PHP Object / Class / Controller for doing that).

    In case of the Leaflet Drupal module this approach is coping the case the user wants to add to the Leaflet Map a GeoJson content/file that is external to the CMS, and indeed without using Drupal controller, PHP Object / class etc. for injecting a Geojson content before going into the JS front-end processing / layer.

    But if you really need to use the a Drupal controller, PHP Object / class etc. (and make your life so complicate, or easy, it depends from points of view) then you are still able to go with it and inject your geojson content into a PHP variable (string, array, whoever) and pass/add it in the ['#attached']drupalSettings property and (STILL, you don't have other options) use in the JS front-end processing / layer.

    Otherwise the GeoJson Geometries data can always be added in a Geofield (that support Goejson string, but only in terms of geometries, and not other additional properties) and make it part of a Drupal Entity/Node content and render it the way you want in the FE (with Leaflet View, or a Field Formatter ... that is still a Controller).

  • 🇮🇹Italy itamair

    BUT ... @b2f if you have a more clear idea and approach on this, please clearly provide your implementation (with a patch, or MR) to the module, so I/the community can clearly understand what you mean and get your constructive contribution.

    May be I was just not able to understand what you mean / meant (so far on this, sorry my fault).

    Only complaining on the way things are working (or not working) here is not the a helping approach.

    In the open source community, everybody is welcome with solid & improving solutions.

  • Status changed to Closed: outdated 11 months ago
Production build 0.71.5 2024