Skip to content

Commit 73553ec

Browse files
committed
Add a dblclick option. Closes #43
1 parent ccd4966 commit 73553ec

File tree

5 files changed

+40
-8
lines changed

5 files changed

+40
-8
lines changed

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,14 +264,24 @@ mymap:
264264

265265
#### 5.10. `language`
266266

267-
If this options is set with an [ISO 639-1 code](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) (en, fr, de, etc.), the geocoding service will return results in the requested language if available. Default is `false`.
267+
If this option is set with an [ISO 639-1 code](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) (en, fr, de, etc.), the geocoding service will return results in the requested language if available. Default is `false`.
268268

269269
```yaml
270270
mymap:
271271
type: locator
272272
language: false # or 'de' | 'fr' | 'en' | …
273273
```
274274

275+
#### 5.11. `dblclick`
276+
277+
Whether a double click on the map should trigger a zoom (`zoom`) or add a marker / move the existing marker to the coordinates of the click event (`marker`). Default is `zoom`.
278+
279+
```yaml
280+
mymap:
281+
type: locator
282+
dblclick: zoom # or 'marker'
283+
```
284+
275285
<br/>
276286

277287
## 6. Global options
@@ -293,6 +303,7 @@ return array(
293303
'sylvainjule.locator.liststyle' => 'columns',
294304
'sylvainjule.locator.marker' => 'dark',
295305
'sylvainjule.locator.language' => false,
306+
'sylvainjule.locator.dblclick' => 'zoom',
296307
);
297308
```
298309

index.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
'saveZoom' => false,
2020
'autoSaveZoom' => false,
2121
'language' => false,
22+
'dblclick' => 'zoom',
2223
),
2324
'fields' => require_once __DIR__ . '/lib/fields.php',
2425
'fieldMethods' => require_once __DIR__ . '/lib/fieldMethods.php',

lib/fields.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@
3939
'language' => function($language = null) {
4040
return $language ?? option('sylvainjule.locator.language');
4141
},
42+
'dblclick' => function($dblclick = null) {
43+
return $dblclick ?? option('sylvainjule.locator.dblclick');
44+
},
4245
'center' => function($center = []) {
4346
return array(
4447
'lat' => $center['lat'] ?? option('sylvainjule.locator.center.lat'),

src/field/Locator.vue

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ export default {
8585
draggable: Boolean,
8686
autocomplete: Boolean,
8787
language: [String, Boolean],
88+
dblclick: String,
8889
8990
// general options
9091
label: String,
@@ -231,7 +232,11 @@ export default {
231232
initMap() {
232233
// init map
233234
let zoom = this.value ? this.value.zoom || this.defaultZoom : this.defaultZoom
234-
this.map = L.map(this.mapId, {minZoom: this.zoom.min, maxZoom: this.zoom.max}).setView(this.defaultCoords, zoom)
235+
236+
this.map = L.map(this.mapId, {
237+
minZoom: this.zoom.min,
238+
maxZoom: this.zoom.max,
239+
}).setView(this.defaultCoords, zoom)
235240
236241
// set the tile layer
237242
this.tileLayer = L.tileLayer(this.tileUrl, {attribution: this.attribution})
@@ -254,6 +259,13 @@ export default {
254259
}, 500)
255260
});
256261
}
262+
263+
if(this.dblclick == 'marker') {
264+
this.map.doubleClickZoom.disable()
265+
this.map.on('dblclick', (e) => {
266+
this.setCoordinates(e.latlng.lat + ',' + e.latlng.lng)
267+
})
268+
}
257269
},
258270
updateMap() {
259271
if(this.map) {
@@ -376,9 +388,10 @@ export default {
376388
return regexExp.test(str);
377389
},
378390
setCoordinates(str) {
379-
let arr = str.split(',')
380-
let lat = arr[0].replace(' ', '')
381-
let lon = arr[1].replace(' ', '')
391+
let arr = str.split(',')
392+
let lat = arr[0].replace(' ', '')
393+
let lon = arr[1].replace(' ', '')
394+
let _this = this
382395
383396
this.value = {
384397
'lat': parseFloat(lat),
@@ -401,6 +414,10 @@ export default {
401414
402415
this.location = ''
403416
this.$emit("input", this.value)
417+
this.dragged = true
418+
setTimeout(() => {
419+
_this.dragged = false
420+
}, 500)
404421
},
405422
setNominatimResponse(response) {
406423
response = response[0]
@@ -463,7 +480,7 @@ export default {
463480
this.map.scrollWheelZoom.enable()
464481
this.map.dragging.enable()
465482
this.map.touchZoom.enable()
466-
this.map.doubleClickZoom.enable()
483+
if(this.dblclick != 'marker') this.map.doubleClickZoom.enable()
467484
this.map.boxZoom.enable()
468485
this.map.keyboard.enable()
469486
if (this.map.tap) this.map.tap.enable()

0 commit comments

Comments
 (0)