Skip to content

Commit

Permalink
Update build.
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtoye committed Jan 24, 2015
1 parent f013e32 commit 07b1448
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 94 deletions.
213 changes: 121 additions & 92 deletions dist/leaflet.draw-src.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ L.drawLocal = {
circle: {
tooltip: {
start: 'Click and drag to draw circle.'
}
},
radius: 'Radius'
},
marker: {
tooltip: {
Expand Down Expand Up @@ -938,7 +939,7 @@ L.Draw.Circle = L.Draw.SimpleShape.extend({

this._tooltip.updateContent({
text: this._endLabelText,
subtext: showRadius ? 'Radius: ' + L.GeometryUtil.readableDistance(radius, useMetric) : ''
subtext: showRadius ? L.drawLocal.draw.handlers.circle.radius + ': ' + L.GeometryUtil.readableDistance(radius, useMetric) : ''
});
}
}
Expand Down Expand Up @@ -1049,6 +1050,83 @@ L.Draw.Marker = L.Draw.Feature.extend({
});


L.Edit = L.Edit || {};

L.Edit.Marker = L.Handler.extend({
initialize: function (marker, options) {
this._marker = marker;
L.setOptions(this, options);
},

addHooks: function () {
var marker = this._marker;

marker.dragging.enable();
marker.on('dragend', this._onDragEnd, marker);
this._toggleMarkerHighlight();
},

removeHooks: function () {
var marker = this._marker;

marker.dragging.disable();
marker.off('dragend', this._onDragEnd, marker);
this._toggleMarkerHighlight();
},

_onDragEnd: function (e) {
var layer = e.target;
layer.edited = true;
},

_toggleMarkerHighlight: function () {

// Don't do anything if this layer is a marker but doesn't have an icon. Markers
// should usually have icons. If using Leaflet.draw with Leafler.markercluster there
// is a chance that a marker doesn't.
if (!this._icon) {
return;
}

// This is quite naughty, but I don't see another way of doing it. (short of setting a new icon)
var icon = this._icon;

icon.style.display = 'none';

if (L.DomUtil.hasClass(icon, 'leaflet-edit-marker-selected')) {
L.DomUtil.removeClass(icon, 'leaflet-edit-marker-selected');
// Offset as the border will make the icon move.
this._offsetMarker(icon, -4);

} else {
L.DomUtil.addClass(icon, 'leaflet-edit-marker-selected');
// Offset as the border will make the icon move.
this._offsetMarker(icon, 4);
}

icon.style.display = '';
},

_offsetMarker: function (icon, offset) {
var iconMarginTop = parseInt(icon.style.marginTop, 10) - offset,
iconMarginLeft = parseInt(icon.style.marginLeft, 10) - offset;

icon.style.marginTop = iconMarginTop + 'px';
icon.style.marginLeft = iconMarginLeft + 'px';
}
});

L.Marker.addInitHook(function () {
if (L.Edit.Marker) {
this.editing = new L.Edit.Marker(this);

if (this.options.editable) {
this.editing.enable();
}
}
});


L.Edit = L.Edit || {};

/*
Expand All @@ -1069,6 +1147,14 @@ L.Edit.Poly = L.Handler.extend({
},

addHooks: function () {
var poly = this._poly;

if (!(poly instanceof L.Polygon)) {
poly.options.editing.fill = false;
}

poly.setStyle(poly.options.editing);

if (this._poly._map) {
if (!this._markerGroup) {
this._initMarkers();
Expand All @@ -1078,8 +1164,12 @@ L.Edit.Poly = L.Handler.extend({
},

removeHooks: function () {
if (this._poly._map) {
this._poly._map.removeLayer(this._markerGroup);
var poly = this._poly;

poly.setStyle(poly.options.original);

if (poly._map) {
poly._map.removeLayer(this._markerGroup);
delete this._markerGroup;
delete this._markers;
}
Expand Down Expand Up @@ -1343,8 +1433,12 @@ L.Edit.SimpleShape = L.Handler.extend({
},

addHooks: function () {
if (this._shape._map) {
this._map = this._shape._map;
var shape = this._shape;

shape.setStyle(shape.options.editing);

if (shape._map) {
this._map = shape._map;

if (!this._markerGroup) {
this._initMarkers();
Expand All @@ -1354,7 +1448,11 @@ L.Edit.SimpleShape = L.Handler.extend({
},

removeHooks: function () {
if (this._shape._map) {
var shape = this._shape;

shape.setStyle(shape.options.original);

if (shape._map) {
this._unbindMarker(this._moveMarker);

for (var i = 0, l = this._resizeMarkers.length; i < l; i++) {
Expand Down Expand Up @@ -2539,8 +2637,7 @@ L.EditToolbar.Edit = L.Handler.extend({
initialize: function (map, options) {
L.Handler.prototype.initialize.call(this, map);

// Set options to the default unless already set
this._selectedPathOptions = options.selectedPathOptions;
L.setOptions(this, options);

// Store the selectable layer group for ease of access
this._featureGroup = options.featureGroup;
Expand Down Expand Up @@ -2666,114 +2763,43 @@ L.EditToolbar.Edit = L.Handler.extend({
} else if (layer instanceof L.Marker) { // Marker
layer.setLatLng(this._uneditedLayerProps[id].latlng);
}
}
},

_toggleMarkerHighlight: function (marker) {
if (!marker._icon) {
return;
layer.fire('revert-edited', { layer: layer });
}
// This is quite naughty, but I don't see another way of doing it. (short of setting a new icon)
var icon = marker._icon;

icon.style.display = 'none';

if (L.DomUtil.hasClass(icon, 'leaflet-edit-marker-selected')) {
L.DomUtil.removeClass(icon, 'leaflet-edit-marker-selected');
// Offset as the border will make the icon move.
this._offsetMarker(icon, -4);

} else {
L.DomUtil.addClass(icon, 'leaflet-edit-marker-selected');
// Offset as the border will make the icon move.
this._offsetMarker(icon, 4);
}

icon.style.display = '';
},

_offsetMarker: function (icon, offset) {
var iconMarginTop = parseInt(icon.style.marginTop, 10) - offset,
iconMarginLeft = parseInt(icon.style.marginLeft, 10) - offset;

icon.style.marginTop = iconMarginTop + 'px';
icon.style.marginLeft = iconMarginLeft + 'px';
},

_enableLayerEdit: function (e) {
var layer = e.layer || e.target || e,
isMarker = layer instanceof L.Marker,
pathOptions;

// Don't do anything if this layer is a marker but doesn't have an icon. Markers
// should usually have icons. If using Leaflet.draw with Leafler.markercluster there
// is a chance that a marker doesn't.
if (isMarker && !layer._icon) {
return;
}

// Back up this layer (if haven't before)
this._backupLayer(layer);

// Update layer style so appears editable
if (this._selectedPathOptions) {
pathOptions = L.Util.extend({}, this._selectedPathOptions);
// Set different style for editing mode
if (this.options.selectedPathOptions) {
pathOptions = L.Util.extend({}, this.options.selectedPathOptions);

// Use the existing color of the layer
if (pathOptions.maintainColor) {
pathOptions.color = layer.options.color;
pathOptions.fillColor = layer.options.fillColor;
}

if (isMarker) {
this._toggleMarkerHighlight(layer);
} else {
layer.options.previousOptions = L.Util.extend({ dashArray: null }, layer.options);

// Make sure that Polylines are not filled
if (!(layer instanceof L.Circle) && !(layer instanceof L.Polygon) && !(layer instanceof L.Rectangle)) {
pathOptions.fill = false;
}

layer.setStyle(pathOptions);
}
layer.options.original = L.extend({}, layer.options);
layer.options.editing = pathOptions;
}

if (isMarker) {
layer.dragging.enable();
layer.on('dragend', this._onMarkerDragEnd);
} else {
layer.editing.enable();
}
layer.editing.enable();
},

_disableLayerEdit: function (e) {
var layer = e.layer || e.target || e;
layer.edited = false;

// Reset layer styles to that of before select
if (this._selectedPathOptions) {
if (layer instanceof L.Marker) {
this._toggleMarkerHighlight(layer);
} else {
// reset the layer style to what is was before being selected
layer.setStyle(layer.options.previousOptions);
// remove the cached options for the layer object
delete layer.options.previousOptions;
}
}

if (layer instanceof L.Marker) {
layer.dragging.disable();
layer.off('dragend', this._onMarkerDragEnd, this);
} else {
layer.editing.disable();
}
},
layer.edited = false;
layer.editing.disable();

_onMarkerDragEnd: function (e) {
var layer = e.target;
layer.edited = true;
delete layer.options.editing;
delete layer.options.original;
},

_onMouseMove: function (e) {
Expand Down Expand Up @@ -2845,7 +2871,7 @@ L.EditToolbar.Delete = L.Handler.extend({
map.getContainer().focus();

this._deletableLayers.eachLayer(this._enableLayerDelete, this);
this._deletedLayers = new L.layerGroup();
this._deletedLayers = new L.LayerGroup();

this._tooltip = new L.Tooltip(this._map);
this._tooltip.updateContent({ text: L.drawLocal.edit.handlers.remove.tooltip.text });
Expand All @@ -2870,6 +2896,7 @@ L.EditToolbar.Delete = L.Handler.extend({
// Iterate of the deleted layers and add them back into the featureGroup
this._deletedLayers.eachLayer(function (layer) {
this._deletableLayers.addLayer(layer);
layer.fire('revert-deleted', { layer: layer });
}, this);
},

Expand Down Expand Up @@ -2898,6 +2925,8 @@ L.EditToolbar.Delete = L.Handler.extend({
this._deletableLayers.removeLayer(layer);

this._deletedLayers.addLayer(layer);

layer.fire('deleted');
},

_onMouseMove: function (e) {
Expand Down
Loading

0 comments on commit 07b1448

Please sign in to comment.