Sha256: 8dde6d03e7db738ef94e99ebc337c67699c9a130626763a2375e6cbaaa5741e8

Contents?: true

Size: 1.14 KB

Versions: 22

Compression:

Stored size: 1.14 KB

Contents

import * as L from "leaflet";
import MapController from "src/decidim/map/controller"
import "src/decidim/vendor/leaflet-tilelayer-here"

export default class MapDragMarkerController extends MapController {
  start() {
    if (this.config.marker) {
      this.addMarker(this.config.marker);
    } else {
      this.map.fitWorld();
    }
  }

  addMarker(markerData) {
    if (markerData.latitude === null || markerData.longitude === null) {
      return;
    }

    const coordinates = {
      lat: markerData.latitude,
      lng: markerData.longitude
    };
    this.triggerEvent("coordinates", [coordinates]);

    this.marker = L.marker(coordinates, {
      icon: this.createIcon(),
      keyboard: true,
      title: markerData.title,
      draggable: true
    });
    this.marker.on("drag", (ev) => {
      this.triggerEvent("coordinates", [ev.target.getLatLng()]);
    });
    this.marker.addTo(this.map);

    const zoom = parseInt(this.config.zoom, 10) || 14;
    this.map.setView(coordinates, zoom);
  }

  getMarker() {
    return this.marker;
  }

  removeMarker() {
    if (this.marker) {
      this.marker.remove();
      this.marker = null;
    }
  }
}

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
decidim-core-0.27.3 app/packs/src/decidim/map/controller/drag_marker.js
decidim-core-0.26.7 app/packs/src/decidim/map/controller/drag_marker.js
decidim-core-0.26.5 app/packs/src/decidim/map/controller/drag_marker.js
decidim-core-0.27.2 app/packs/src/decidim/map/controller/drag_marker.js
decidim-core-0.27.1 app/packs/src/decidim/map/controller/drag_marker.js
decidim-core-0.26.4 app/packs/src/decidim/map/controller/drag_marker.js
decidim-core-0.27.0 app/packs/src/decidim/map/controller/drag_marker.js
decidim-core-0.26.3 app/packs/src/decidim/map/controller/drag_marker.js
decidim-core-0.27.0.rc2 app/packs/src/decidim/map/controller/drag_marker.js
decidim-core-0.27.0.rc1 app/packs/src/decidim/map/controller/drag_marker.js
decidim-core-0.26.2 app/packs/src/decidim/map/controller/drag_marker.js
decidim-core-0.26.1 app/packs/src/decidim/map/controller/drag_marker.js
decidim-core-0.26.0 app/packs/src/decidim/map/controller/drag_marker.js
decidim-core-0.26.0.rc2 app/packs/src/decidim/map/controller/drag_marker.js
decidim-core-0.26.0.rc1 app/packs/src/decidim/map/controller/drag_marker.js
decidim-core-0.25.2 app/packs/src/decidim/map/controller/drag_marker.js
decidim-core-0.25.1 app/packs/src/decidim/map/controller/drag_marker.js
decidim-core-0.25.0 app/packs/src/decidim/map/controller/drag_marker.js
decidim-core-0.25.0.rc4 app/packs/src/decidim/map/controller/drag_marker.js
decidim-core-0.25.0.rc3 app/packs/src/decidim/map/controller/drag_marker.js