- }
- },
-
- _addHooks: function () {
- L.DomEvent.addListener(document, 'keydown', this._onKeyDown, this);
- },
-
- _removeHooks: function () {
- L.DomEvent.removeListener(document, 'keydown', this._onKeyDown, this);
- },
-
- _onKeyDown: function (e) {
- var key = e.keyCode;
-
- if (this._panKeys.hasOwnProperty(key)) {
- this._map.panBy(this._panKeys[key]);
-
- } else if (this._zoomKeys.hasOwnProperty(key)) {
- this._map.setZoom(this._map.getZoom() + this._zoomKeys[key]);
-
- } else {
- return;
- }
-
- L.DomEvent.stop(e);
- }
-});
-
-L.Map.addInitHook('addHandler', 'keyboard', L.Map.Keyboard);
-
-
-/*
- * L.Handler.MarkerDrag is used internally by L.Marker to make the markers draggable.
- */
-
-L.Handler.MarkerDrag = L.Handler.extend({
- initialize: function (marker) {
- this._marker = marker;
- },
-
- addHooks: function () {
- var icon = this._marker._icon;
- if (!this._draggable) {
- this._draggable = new L.Draggable(icon, icon)
- .on('dragstart', this._onDragStart, this)
- .on('drag', this._onDrag, this)
- .on('dragend', this._onDragEnd, this);
- }
- this._draggable.enable();
- },
-
- removeHooks: function () {
- this._draggable.disable();
- },
-
- moved: function () {
- return this._draggable && this._draggable._moved;
- },
-
- _onDragStart: function (e) {
- this._marker
- .closePopup()
- .fire('movestart')
- .fire('dragstart');
- },
-
- _onDrag: function (e) {
- var marker = this._marker,
- shadow = marker._shadow,
- iconPos = L.DomUtil.getPosition(marker._icon),
- latlng = marker._map.layerPointToLatLng(iconPos);
-
- // update shadow position
- if (shadow) {
- L.DomUtil.setPosition(shadow, iconPos);
- }
-
- marker._latlng = latlng;
-
- marker
- .fire('move', { latlng: latlng })
- .fire('drag');
- },
-
- _onDragEnd: function () {
- this._marker
- .fire('moveend')
- .fire('dragend');
- }
-});
-
-
-L.Handler.PolyEdit = L.Handler.extend({
- options: {
- icon: new L.DivIcon({
- iconSize: new L.Point(8, 8),
- className: 'leaflet-div-icon leaflet-editing-icon'
- })
- },
-
- initialize: function (poly, options) {
- this._poly = poly;
- L.Util.setOptions(this, options);
- },
-
- addHooks: function () {
- if (this._poly._map) {
- if (!this._markerGroup) {
- this._initMarkers();
- }
- this._poly._map.addLayer(this._markerGroup);
- }
- },
-
- removeHooks: function () {
- if (this._poly._map) {
- this._poly._map.removeLayer(this._markerGroup);
- delete this._markerGroup;
- delete this._markers;
- }
- },
-
- updateMarkers: function () {
- this._markerGroup.clearLayers();
- this._initMarkers();
- },
-
- _initMarkers: function () {
- if (!this._markerGroup) {
- this._markerGroup = new L.LayerGroup();
- }
- this._markers = [];
-
- var latlngs = this._poly._latlngs,
- i, j, len, marker;
-
- // TODO refactor holes implementation in Polygon to support it here
-
- for (i = 0, len = latlngs.length; i < len; i++) {
-
- marker = this._createMarker(latlngs[i], i);
- marker.on('click', this._onMarkerClick, this);
- this._markers.push(marker);
- }
-
- var markerLeft, markerRight;
-
- for (i = 0, j = len - 1; i < len; j = i++) {
- if (i === 0 && !(L.Polygon && (this._poly instanceof L.Polygon))) {
- continue;
- }
-
- markerLeft = this._markers[j];
- markerRight = this._markers[i];
-
- this._createMiddleMarker(markerLeft, markerRight);
- this._updatePrevNext(markerLeft, markerRight);
- }
- },
-
- _createMarker: function (latlng, index) {
- var marker = new L.Marker(latlng, {
- draggable: true,
- icon: this.options.icon
- });
-
- marker._origLatLng = latlng;
- marker._index = index;
-
- marker.on('drag', this._onMarkerDrag, this);
- marker.on('dragend', this._fireEdit, this);
-
- this._markerGroup.addLayer(marker);