| | |
| | | initialize: function(path) { |
| | | this._path = path |
| | | this._canvas = (path._map.getRenderer(path) instanceof L.Canvas) |
| | | let element = this._canvas ? this._path._map.getRenderer(this._path)._container : this._path._path |
| | | const element = this._canvas ? this._path._map.getRenderer(this._path)._container : this._path._path |
| | | L.Draggable.prototype.initialize.call(this, element, element, true) |
| | | }, |
| | | |
| | | _updatePosition: function() { |
| | | let e = { originalEvent: this._lastEvent } |
| | | const e = { originalEvent: this._lastEvent } |
| | | this.fire('drag', e) |
| | | }, |
| | | |
| | | _onDown: function(e) { |
| | | let first = e.touches ? e.touches[0] : e |
| | | const first = e.touches ? e.touches[0] : e |
| | | this._startPoint = new L.Point(first.clientX, first.clientY) |
| | | if (this._canvas && !this._path._containsPoint(this._path._map.mouseEventToLayerPoint(first))) { |
| | | return |
| | |
| | | }, |
| | | |
| | | _onDrag: function(e) { |
| | | let path = this._path |
| | | let event = (e.originalEvent.touches && e.originalEvent.touches.length === 1 ? e.originalEvent.touches[0] : e.originalEvent) |
| | | let newPoint = L.point(event.clientX, event.clientY) |
| | | let latlng = path._map.layerPointToLatLng(newPoint) |
| | | const path = this._path |
| | | const event = (e.originalEvent.touches && e.originalEvent.touches.length === 1 ? e.originalEvent.touches[0] : e.originalEvent) |
| | | const newPoint = L.point(event.clientX, event.clientY) |
| | | const latlng = path._map.layerPointToLatLng(newPoint) |
| | | |
| | | this._offset = newPoint.subtract(this._startPoint) |
| | | this._startPoint = newPoint |
| | |
| | | |
| | | latLngToLayerPoint: function(latlng) { |
| | | // Same as map.latLngToLayerPoint, but without the round(). |
| | | let projectedPoint = this._path._map.project(L.latLng(latlng)) |
| | | const projectedPoint = this._path._map.project(L.latLng(latlng)) |
| | | return projectedPoint._subtract(this._path._map.getPixelOrigin()) |
| | | }, |
| | | |
| | | updateLatLng: function(latlng) { |
| | | let oldPoint = this.latLngToLayerPoint(latlng) |
| | | const oldPoint = this.latLngToLayerPoint(latlng) |
| | | oldPoint._add(this._offset) |
| | | let newLatLng = this._path._map.layerPointToLatLng(oldPoint) |
| | | const newLatLng = this._path._map.layerPointToLatLng(oldPoint) |
| | | latlng.lat = newLatLng.lat |
| | | latlng.lng = newLatLng.lng |
| | | }, |
| | |
| | | |
| | | eachLatLng: function(callback, context) { |
| | | context = context || this |
| | | let loop = function(latlngs) { |
| | | const loop = function (latlngs) { |
| | | for (let i = 0; i < latlngs.length; i++) { |
| | | if (L.Util.isArray(latlngs[i])) loop(latlngs[i]) |
| | | else callback.call(context, latlngs[i]) |