Sha256: 31ca22ad329bdf9e4b4a850dc29a872227287f1e3e7e332211ba1f068614e651

Contents?: true

Size: 1.75 KB

Versions: 8

Compression:

Stored size: 1.75 KB

Contents

((exports) => {
  exports.Decidim = exports.Decidim || {};

  const MapController = exports.Decidim.MapController;

  class MapMarkersController extends MapController {
    start() {
      this.markerClusters = null;

      if (Array.isArray(this.config.markers) && this.config.markers.length > 0) {
        this.addMarkers(this.config.markers);
      } else {
        this.map.fitWorld();
      }
    }

    addMarkers(markersData) {
      if (this.markerClusters === null) {
        this.markerClusters = L.markerClusterGroup();
        this.map.addLayer(this.markerClusters);
      }

      // Pre-compiles the template
      $.template(
        this.config.popupTemplateId,
        $(`#${this.config.popupTemplateId}`).html()
      );

      const bounds = new L.LatLngBounds(
        markersData.map(
          (markerData) => [markerData.latitude, markerData.longitude]
        )
      );

      markersData.forEach((markerData) => {
        let marker = L.marker([markerData.latitude, markerData.longitude], {
          icon: this.createIcon(),
          keyboard: true,
          title: markerData.title
        });
        let node = document.createElement("div");

        $.tmpl(this.config.popupTemplateId, markerData).appendTo(node);
        marker.bindPopup(node, {
          maxwidth: 640,
          minWidth: 500,
          keepInView: true,
          className: "map-info"
        }).openPopup();

        this.markerClusters.addLayer(marker);
      });

      this.map.fitBounds(bounds, { padding: [100, 100] });
    }

    clearMarkers() {
      this.map.removeLayer(this.markerClusters);
      this.markerClusters = L.markerClusterGroup();
      this.map.addLayer(this.markerClusters);
    }
  }

  exports.Decidim.MapMarkersController = MapMarkersController;
})(window);

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
decidim-core-0.23.6 app/assets/javascripts/decidim/map/controller/markers.js.es6
decidim-core-0.23.5 app/assets/javascripts/decidim/map/controller/markers.js.es6
decidim-core-0.23.4 app/assets/javascripts/decidim/map/controller/markers.js.es6
decidim-core-0.23.3 app/assets/javascripts/decidim/map/controller/markers.js.es6
decidim-core-0.23.2 app/assets/javascripts/decidim/map/controller/markers.js.es6
decidim-core-0.23.1 app/assets/javascripts/decidim/map/controller/markers.js.es6
decidim-core-0.23.1.rc1 app/assets/javascripts/decidim/map/controller/markers.js.es6
decidim-core-0.23.0 app/assets/javascripts/decidim/map/controller/markers.js.es6