Sha256: b96f59a0efffbe5141440d5dfc05070f6b7c8a0ad4ad744a9edcc722cdb828b0

Contents?: true

Size: 1.59 KB

Versions: 9

Compression:

Stored size: 1.59 KB

Contents

import MapControllerRegistry from "src/decidim/map/controller_registry"

export default class MapController {
  constructor(mapId, config) {
    // Remove the old map if there is already one with the same ID.
    const old = MapControllerRegistry.getController(mapId);
    if (old) {
      old.remove();
    }

    this.mapId = mapId;
    this.config = $.extend({
      popupTemplateId: "marker-popup",
      markerColor: "#ef604d"
    }, config);

    this.map = null;
    this.eventHandlers = {};

    MapControllerRegistry.setController(mapId, this);
  }

  getConfig() {
    return this.config;
  }

  getMap() {
    return this.map;
  }

  load() {
    this.map = L.map(this.mapId);

    this.map.scrollWheelZoom.disable();

    // Fix the keyboard navigation on the map
    this.map.on("popupopen", (ev) => {
      const $popup = $(ev.popup.getElement());
      $popup.attr("tabindex", 0).focus();
    });
    this.map.on("popupclose", (ev) => {
      $(ev.popup._source._icon).focus();
    });

    return this.map;
  }

  // Override this in the specific map controllers.
  start() {}

  remove() {
    if (this.map) {
      this.map.remove();
      this.map = null;
    }
  }

  createIcon() {
    return new L.DivIcon.SVGIcon.DecidimIcon({
      fillColor: this.config.markerColor,
      iconSize: L.point(28, 36)
    });
  }

  setEventHandler(name, callback) {
    this.eventHandlers[name] = callback;
  }

  triggerEvent(eventName, payload) {
    const handler = this.eventHandlers[eventName];
    if (typeof handler === "function") {
      return Reflect.apply(handler, this, payload);
    }
    return null;
  }
}

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
decidim-core-0.27.9 app/packs/src/decidim/map/controller.js
decidim-core-0.27.8 app/packs/src/decidim/map/controller.js
decidim-core-0.27.7 app/packs/src/decidim/map/controller.js
decidim-core-0.27.6 app/packs/src/decidim/map/controller.js
decidim-core-0.26.10 app/packs/src/decidim/map/controller.js
decidim-core-0.26.9 app/packs/src/decidim/map/controller.js
decidim-core-0.27.5 app/packs/src/decidim/map/controller.js
decidim-core-0.26.8 app/packs/src/decidim/map/controller.js
decidim-core-0.27.4 app/packs/src/decidim/map/controller.js