Unverified Commit 76aa9177 authored by Hoi Sing Edison Wong's avatar Hoi Sing Edison Wong
Browse files

Issue #3252629 by hswong3i: Add domoritz/leaflet-locatecontrol Support

Refer to https://www.drupal.org/project/leaflet/issues/3236815
suggestion, in order to make use of GeoField proximity filtering and
ordering, a meaningful "Origin Coordinates" for end-user is important,
e.g.:

  - A manual default origin coordinate
  - Center of map after end-user moving the map by mouse click-and-move
  - The client location through the browser HTML5 Geolocation API (e.g.
    by GPS, IP, etc)

This PR add support for Leaflet with Geolocation functionality, by
introduce https://github.com/domoritz/leaflet-locatecontrol


integration.

Signed-off-by: default avatarWong Hoi Sing Edison <hswong3i@pantarei-design.com>
parent ee25dfff
Loading
Loading
Loading
Loading
+20 −3
Original line number Diff line number Diff line
@@ -14,9 +14,6 @@ field.widget.settings.leaflet_widget_default:
        height:
          type: integer
          label: 'Height'
        locate:
          type: integer
          label: 'Locale'
        auto_center:
          type: integer
          label: 'Automatically center map'
@@ -122,6 +119,16 @@ field.widget.settings.leaflet_widget_default:
        options:
          type: text
          label: 'Options'
    locate:
      type: mapping
      label: 'Leaflet Locate'
      mapping:
        control:
          type: boolean
          label: 'Control'
        options:
          type: text
          label: 'Options'
    path:
      type: text
      label: 'Path'
@@ -342,6 +349,16 @@ field.formatter.settings.leaflet_formatter_default:
        options:
          type: text
          label: 'Options'
    locate:
      type: mapping
      label: 'Leaflet Locate'
      mapping:
        control:
          type: boolean
          label: 'Control'
        options:
          type: text
          label: 'Options'
    path:
      type: text
      label: 'Path'
+7 −0
Original line number Diff line number Diff line
@@ -164,6 +164,13 @@
      ).addTo(self.lMap);
    }

    // Add Locate Control, if requested.
    if (self.settings.locate.control) {
      L.control.locate(
        JSON.parse(self.settings.locate.options)
      ).addTo(self.lMap);
    }

  };

  Drupal.Leaflet.prototype.initialise_layer_control = function(mapid) {
+1 −1
Original line number Diff line number Diff line
@@ -159,7 +159,7 @@
    if (value.length === 0) {

      // If no layer available, locate the user position.
      if (this.settings.locate && !this.settings.map_position.force) {
      if (this.settings.locate.control && !this.settings.map_position.force) {
        this.map.locate({setView: true, maxZoom: 18});
      }

+14 −0
Original line number Diff line number Diff line
@@ -105,3 +105,17 @@ leaflet.geocoder:
  dependencies:
    - core/drupal.autocomplete
    - leaflet/leaflet-drupal

leaflet.locate:
  remote: https://github.com/domoritz/leaflet-locatecontrol
  license:
    name: MIT
    url: https://raw.githubusercontent.com/domoritz/leaflet-locatecontrol/gh-pages/LICENSE
    gpl-compatible: yes
  css:
    component:
      /libraries/leaflet.locatecontrol/dist/L.Control.Locate.min.css: { minified: true }
  js:
    /libraries/leaflet.locatecontrol/dist/L.Control.Locate.min.js: { minified: true }
  dependencies:
    - leaflet/leaflet
+10 −0
Original line number Diff line number Diff line
@@ -177,6 +177,16 @@ views.style.leaflet_map:
        options:
          type: text
          label: 'Options'
    locate:
      type: mapping
      label: 'Leaflet Locate'
      mapping:
        control:
          type: boolean
          label: 'Control'
        options:
          type: text
          label: 'Options'
    path:
      type: string
      label: 'Path'
Loading