Skip to content

Commit 10f8782

Browse files
committed
Add leaflet-gesture-handling.js leaflet plugin
1 parent 97b71c0 commit 10f8782

File tree

7 files changed

+566
-5
lines changed

7 files changed

+566
-5
lines changed

app/assets/config/better_together_manifest.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
//= link_tree ../../javascript .js
44
//= link_tree ../stylesheets .css
5+
//= link_tree ../../../vendor/stylesheets .css
56
//= link_tree ../stylesheets .scss
67
//= link_tree ../images
78

@@ -19,4 +20,5 @@
1920
//= link imagesloaded.min.js
2021

2122
//= link leaflet.js
23+
//= link leaflet-gesture-handling.js
2224
//= link leaflet-providers.js

app/assets/stylesheets/better_together/application.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* files in this directory. Styles in this file should be added after the last require_* statement.
1111
* It is generally better to create a new file per style scope.
1212
*
13+
*= require leaflet-gesture-handling.min
1314
*= require_self
1415
*/
1516

app/javascript/controllers/better_together/map_controller.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
// Polyfill for `global` to fix compatibility issues with leaflet-gesture-handling
2+
13
// app/javascript/controllers/better_together/map_controller.js
2-
import { Controller } from "@hotwired/stimulus"
4+
import { Controller } from '@hotwired/stimulus'
35
import L from 'leaflet'
6+
import 'leaflet-gesture-handling' // Import the library to ensure it is loaded globally
47

58
export default class extends Controller {
69
static values = {
@@ -26,7 +29,10 @@ export default class extends Controller {
2629
}
2730

2831
initializeMap(center, zoom, extent) {
29-
this.map = L.map(this.element).setView(center, zoom)
32+
this.map = L.map(this.element, {
33+
gestureHandling: true // Enable gesture handling
34+
}).setView(center, zoom)
35+
3036
this.osmLayer = L.tileLayer.provider('OpenStreetMap.Mapnik').addTo(this.map)
3137
this.satelliteLayer = L.tileLayer.provider('Esri.WorldImagery')
3238

@@ -36,6 +42,7 @@ export default class extends Controller {
3642
}
3743

3844
this.addPointsWithLabels(this.spacesValue)
45+
3946
// this.map.on('click', (e) => {
4047
// console.log(`Map clicked at: ${e.latlng}`)
4148
// })
@@ -60,7 +67,7 @@ export default class extends Controller {
6067

6168
const success = (pos) => {
6269
const crd = pos.coords
63-
console.log("Your current position is:")
70+
console.log('Your current position is:')
6471
console.log(`Latitude : ${crd.latitude}`)
6572
console.log(`Longitude: ${crd.longitude}`)
6673
console.log(`More or less ${crd.accuracy} meters.`)

bin/importmap

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
3+
4+
# require_relative '../config/application'
5+
require_relative '../lib/better_together/engine'
6+
require 'importmap/commands'

config/importmap.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@
3232
pin 'masonry', to: 'masonry.min.js' # @4.2.2
3333
pin 'imagesloaded', to: 'imagesloaded.min.js' # @5.0.0
3434

35-
pin 'leaflet' # @1.9.4
36-
pin 'leaflet-providers' # @2.0.0
35+
pin 'leaflet', preload: true # @1.9.4
36+
pin 'leaflet-gesture-handling', to: 'leaflet-gesture-handling.js', preload: true # Ensure it is preloaded # @1.2.2
37+
pin 'leaflet-providers', preload: true # @2.0.0
3738
# pin "trix" # @2.1.13
3839

3940
# Optional: Module shims

vendor/javascript/leaflet-gesture-handling.js

Lines changed: 543 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@-webkit-keyframes leaflet-gestures-fadein{0%{opacity:0}100%{opacity:1}}@keyframes leaflet-gestures-fadein{0%{opacity:0}100%{opacity:1}}.leaflet-container:after{-webkit-animation:leaflet-gestures-fadein .8s backwards;animation:leaflet-gestures-fadein .8s backwards;color:#fff;font-family:Roboto,Arial,sans-serif;font-size:22px;-webkit-box-pack:center;-ms-flex-pack:center;justify-content:center;display:-webkit-box;display:-ms-flexbox;display:flex;-webkit-box-align:center;-ms-flex-align:center;align-items:center;padding:15px;position:absolute;top:0;left:0;right:0;bottom:0;background:rgba(0,0,0,.5);z-index:461;pointer-events:none}.leaflet-gesture-handling-scroll-warning:after,.leaflet-gesture-handling-touch-warning:after{-webkit-animation:leaflet-gestures-fadein .8s forwards;animation:leaflet-gestures-fadein .8s forwards}.leaflet-gesture-handling-touch-warning:after{content:attr(data-gesture-handling-touch-content)}.leaflet-gesture-handling-scroll-warning:after{content:attr(data-gesture-handling-scroll-content)}

0 commit comments

Comments
 (0)