Recenter marker on map pan/zoom
This commit is contained in:
parent
49b0dd4af5
commit
a89d75d3d8
2 changed files with 36 additions and 6 deletions
|
@ -206,8 +206,9 @@ L.OSM.share = function (options) {
|
|||
.on('change', update)
|
||||
.addTo(map);
|
||||
|
||||
marker.on('dragend', movedMarker);
|
||||
map.on('move', movedMap);
|
||||
map.on('moveend layeradd layerremove', update);
|
||||
marker.on('dragend', update);
|
||||
|
||||
options.sidebar.addPane($ui);
|
||||
|
||||
|
@ -216,6 +217,7 @@ L.OSM.share = function (options) {
|
|||
|
||||
function hidden() {
|
||||
map.removeLayer(marker);
|
||||
map.options.scrollWheelZoom = map.options.doubleClickZoom = true;
|
||||
locationFilter.disable();
|
||||
update();
|
||||
}
|
||||
|
@ -235,8 +237,10 @@ L.OSM.share = function (options) {
|
|||
if ($(this).is(':checked')) {
|
||||
marker.setLatLng(map.getCenter());
|
||||
map.addLayer(marker);
|
||||
map.options.scrollWheelZoom = map.options.doubleClickZoom = 'center';
|
||||
} else {
|
||||
map.removeLayer(marker);
|
||||
map.options.scrollWheelZoom = map.options.doubleClickZoom = true;
|
||||
}
|
||||
update();
|
||||
}
|
||||
|
@ -251,11 +255,26 @@ L.OSM.share = function (options) {
|
|||
update();
|
||||
}
|
||||
|
||||
function update() {
|
||||
function movedMap() {
|
||||
marker.setLatLng(map.getCenter());
|
||||
update();
|
||||
}
|
||||
|
||||
function movedMarker() {
|
||||
if (map.hasLayer(marker)) {
|
||||
map.off('move', movedMap);
|
||||
map.on('moveend', updateOnce);
|
||||
map.panTo(marker.getLatLng());
|
||||
}
|
||||
}
|
||||
|
||||
function updateOnce() {
|
||||
map.off('moveend', updateOnce);
|
||||
map.on('move', movedMap);
|
||||
update();
|
||||
}
|
||||
|
||||
function update() {
|
||||
var bounds = map.getBounds();
|
||||
|
||||
$('#link_marker')
|
||||
|
|
19
vendor/assets/leaflet/leaflet.js
vendored
19
vendor/assets/leaflet/leaflet.js
vendored
|
@ -6765,15 +6765,22 @@ L.Map.mergeOptions({
|
|||
|
||||
L.Map.DoubleClickZoom = L.Handler.extend({
|
||||
addHooks: function () {
|
||||
this._map.on('dblclick', this._onDoubleClick);
|
||||
this._map.on('dblclick', this._onDoubleClick, this);
|
||||
},
|
||||
|
||||
removeHooks: function () {
|
||||
this._map.off('dblclick', this._onDoubleClick);
|
||||
this._map.off('dblclick', this._onDoubleClick, this);
|
||||
},
|
||||
|
||||
_onDoubleClick: function (e) {
|
||||
this.setZoomAround(e.containerPoint, this._zoom + 1);
|
||||
var map = this._map,
|
||||
zoom = map.getZoom() + 1;
|
||||
|
||||
if (map.options.doubleClickZoom === 'center') {
|
||||
map.setZoom(zoom);
|
||||
} else {
|
||||
map.setZoomAround(e.containerPoint, zoom);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -6833,7 +6840,11 @@ L.Map.ScrollWheelZoom = L.Handler.extend({
|
|||
|
||||
if (!delta) { return; }
|
||||
|
||||
map.setZoomAround(this._lastMousePos, zoom + delta);
|
||||
if (map.options.scrollWheelZoom === 'center') {
|
||||
map.setZoom(zoom + delta);
|
||||
} else {
|
||||
map.setZoomAround(this._lastMousePos, zoom + delta);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue