Problem/Motivation

On a DrupalCMS 2.1.0 instance, the modules Leaflet, Geofield and Leaflet More Maps work as designed because DrupalCMS is powered by Drupal 11. But when you want to use Drupal Canvas in the same instance to implement a map, you have to add a custom component. Using Claude, the custom component has been implemented with some features. Now, please allow me to be bold: there is zero chance I could have implemented this custom component without Claude. Besides that, other features of the Leaflet module (enable the Leaflet Fullscreen JS Library, for instance) also have to be coded with AI.

Because Drupal Canvas has a promising future, I wonder if creating a Leaflet component could be in the pipe.

Steps to reproduce

Create a custom content type
Create a Geofield field named "Emplacement"
Populate your website with at least one node using this content type
In /canvas of your instance, go to Code > New > Code Component
Add two props: latitude and longitude (see props.png)
Type the following code in the Javascript editor:

const Component = ({
  latitude = 50.1833,
  longitude = 5.5833,
}) => {
  const initMap = (el) => {
    if (!el || el._mapInitialized) return;
    el._mapInitialized = true;

    const startMap = (L) => {
      const map = L.map(el, {
        scrollWheelZoom: false,  // désactive molette
      }).setView([latitude, longitude], 13);

      L.tileLayer('https://{s}.tile.opentopomap.org/{z}/{x}/{y}.png', {
        maxZoom: 17,
        attribution: '© OpenStreetMap contributors, © OpenTopoMap (CC-BY-SA)'
      }).addTo(map);

      L.marker([latitude, longitude]).addTo(map);
      L.control.scale({ imperial: false }).addTo(map);  // scale bar
    };

    if (window.L) {
      startMap(window.L);
    } else {
      const link = document.createElement('link');
      link.rel = 'stylesheet';
      link.href = 'https://unpkg.com/leaflet@1.9.4/dist/leaflet.css';
      document.head.appendChild(link);
      const script = document.createElement('script');
      script.src = 'https://unpkg.com/leaflet@1.9.4/dist/leaflet.js';
      script.onload = () => startMap(window.L);
      document.head.appendChild(script);
    }
  };

  return <div ref={initMap} style={{ width: "100%", height: "400px" }} />;
};

export default Component;

Save changes and perform a drush cr
In /canvas, create a new template for your content type
In Library, add the "Emplacement" component in the desired section
In the settings (see settings.png), map the latitude with "Centroid Latitude" and the longitude with "Centroid Longitude"
Save and visit your node (see result.png)

Comments

gillesbailleux created an issue. See original summary.

itamair’s picture

Status: Active » Closed (won't fix)

Hi @gillesbailleux, thx for reporting this Future Request.

But no, a Leaflet component for Drupal Canvas is not in the actual road map,
because:
- it sounds to me pretty complicate (and very laborious) to replicate in a component for Drupal Canvas what the Leaflet Module does, (with all its settings and styled renderings)
- and I am not even sure what would it mean and how could be it accomplishable, at the moment.

What the Drupal Leaflet module does, basically?
It provides:

  • a Leaflet js formatter (with a lot of settings) upon the Geofield Field type;
  • a Leaflet View Style (with a lot of settings) upon a list of entities (not only nodes) provided by (one or more) Geofield Field types;

Drupal Canvas looks a very powerful tool, but also a brand new front-end layer with many complexities and a lot of open issues / incompatibilities with the Drupal data model and its core functionalities.
That’s why the Drupal Canvas community is working now hardly on the mapping of (still unsupported) Drupal field types into Drupal Canvas Components (and not really viceversa) besides other major issues r(such as lack of support for multivalue fields, multinguism, etc.)

And though I can confirm the good news already identified by the community on this side, that also include the Drupal Leaflet modul:.

Closing this as "Won't fix."

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

gillesbailleux’s picture

Status: Closed (won't fix) » Fixed
StatusFileSize
new15.92 KB
new26.8 KB
new605.91 KB

@itamair: thank you for taking the time to answer me. As you may know, @thejimbirch fixed this issue in a remarquable move via Slack. Let me explain this:
- create a custom Leaflet map view for your custom content type with the "Emplacement" field
- visit /canvas and select the template for your content type
- in the Library section, you will see a new "Views section" (see views-section.png) with the name of the view you created
- insert the view and configure the settings (see view-settings.png)
- exit Canvas and visit your node with the custom map with all the settings, features and customizations provided by the Leaflet module (see new-result.png)

I mark this issue as fixed.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.