draw-tools: convert circles to geodesic mode, to match everything else

perhaps could be a bit cleaner, but it'll do for now...
This commit is contained in:
Jon Atkins 2013-10-16 02:17:13 +01:00
parent 51b24386e6
commit c3b6461d47
2 changed files with 39 additions and 19 deletions

View File

@ -822,7 +822,7 @@ L.Draw.Circle = L.Draw.SimpleShape.extend({
_drawShape: function (latlng) {
if (!this._shape) {
this._shape = new L.Circle(this._startLatLng, this._startLatLng.distanceTo(latlng), this.options.shapeOptions);
this._shape = new L.GeodesicCircle(this._startLatLng, this._startLatLng.distanceTo(latlng), this.options.shapeOptions);
this._map.addLayer(this._shape);
} else {
this._shape.setRadius(this._startLatLng.distanceTo(latlng));
@ -830,7 +830,7 @@ L.Draw.Circle = L.Draw.SimpleShape.extend({
},
_fireCreatedEvent: function () {
var circle = new L.Circle(this._startLatLng, this._shape.getRadius(), this.options.shapeOptions);
var circle = new L.GeodesicCircle(this._startLatLng, this._shape.getRadius(), this.options.shapeOptions);
L.Draw.SimpleShape.prototype._fireCreatedEvent.call(this, circle);
},
@ -1502,10 +1502,8 @@ L.Edit.Circle = L.Edit.SimpleShape.extend({
},
_getResizeMarkerPoint: function (latlng) {
// From L.shape.getBounds()
var delta = this._shape._radius * Math.cos(Math.PI / 4),
point = this._map.project(latlng);
return this._map.unproject([point.x + delta, point.y - delta]);
var latRadius = (this._shape.getRadius() / 40075017) * 360;
return L.latLng(latlng.lat+latRadius,latlng.lng);
},
_move: function (latlng) {
@ -1548,6 +1546,28 @@ L.Circle.addInitHook(function () {
});
});
L.GeodesicCircle.addInitHook(function () {
if (L.Edit.Circle) {
this.editing = new L.Edit.Circle(this);
if (this.options.editable) {
this.editing.enable();
}
}
this.on('add', function () {
if (this.editing && this.editing.enabled()) {
this.editing.addHooks();
}
});
this.on('remove', function () {
if (this.editing && this.editing.enabled()) {
this.editing.removeHooks();
}
});
});
/*
* L.LatLngUtil contains different utility functions for LatLngs.
*/
@ -2432,16 +2452,16 @@ L.EditToolbar.Edit = L.Handler.extend({
var id = L.Util.stamp(layer);
if (!this._uneditedLayerProps[id]) {
// Polyline, Polygon or Rectangle
if (layer instanceof L.GeodesicPolyline || layer instanceof L.GeodesicPolygon || layer instanceof L.Rectangle) {
this._uneditedLayerProps[id] = {
latlngs: L.LatLngUtil.cloneLatLngs(layer.getLatLngs())
};
} else if (layer instanceof L.Circle) {
if (layer instanceof L.GeodesicCircle || layer instanceof L.Circle) {
this._uneditedLayerProps[id] = {
latlng: L.LatLngUtil.cloneLatLng(layer.getLatLng()),
radius: layer.getRadius()
};
} else if (layer instanceof L.GeodesicPolyline || layer instanceof L.GeodesicPolygon || layer instanceof L.Rectangle) {
// Polyline, Polygon or Rectangle
this._uneditedLayerProps[id] = {
latlngs: L.LatLngUtil.cloneLatLngs(layer.getLatLngs())
};
} else { // Marker
this._uneditedLayerProps[id] = {
latlng: L.LatLngUtil.cloneLatLng(layer.getLatLng())
@ -2454,12 +2474,12 @@ L.EditToolbar.Edit = L.Handler.extend({
var id = L.Util.stamp(layer);
layer.edited = false;
if (this._uneditedLayerProps.hasOwnProperty(id)) {
// Polyline, Polygon or Rectangle
if (layer instanceof L.GeodesicPolyline || layer instanceof L.GeodesicPolygon || layer instanceof L.Rectangle) {
layer.setLatLngs(this._uneditedLayerProps[id].latlngs);
} else if (layer instanceof L.Circle) {
if (layer instanceof L.GeodesicCircle || layer instanceof L.Circle) {
layer.setLatLng(this._uneditedLayerProps[id].latlng);
layer.setRadius(this._uneditedLayerProps[id].radius);
} else if (layer instanceof L.GeodesicPolyline || layer instanceof L.GeodesicPolygon || layer instanceof L.Rectangle) {
// Polyline, Polygon or Rectangle
layer.setLatLngs(this._uneditedLayerProps[id].latlngs);
} else { // Marker
layer.setLatLng(this._uneditedLayerProps[id].latlng);
}
@ -2522,7 +2542,7 @@ L.EditToolbar.Edit = L.Handler.extend({
layer.options.previousOptions = layer.options;
// Make sure that Polylines are not filled
if (!(layer instanceof L.Circle) && !(layer instanceof L.GeodesicPolygon) && !(layer instanceof L.Rectangle)) {
if (!(layer instanceof L.Circle) && !(layer instanceof L.GeodrsicCircle) && !(layer instanceof L.GeodesicPolygon) && !(layer instanceof L.Rectangle)) {
pathOptions.fill = false;
}

View File

@ -2,7 +2,7 @@
// @id iitc-plugin-draw-tools@breunigs
// @name IITC plugin: draw tools
// @category Layer
// @version 0.5.1.@@DATETIMEVERSION@@
// @version 0.5.2.@@DATETIMEVERSION@@
// @namespace https://github.com/jonatkins/ingress-intel-total-conversion
// @updateURL @@UPDATEURL@@
// @downloadURL @@DOWNLOADURL@@
@ -197,7 +197,7 @@ window.plugin.drawTools.load = function() {
layer = L.geodesicPolygon(item.latLngs,window.plugin.drawTools.polygonOptions);
break;
case 'circle':
layer = L.circle(item.latLng,item.radius,window.plugin.drawTools.polygonOptions);
layer = L.geodesicCircle(item.latLng,item.radius,window.plugin.drawTools.polygonOptions);
break;
case 'marker':
layer = L.marker(item.latLng,window.plugin.drawTools.markerOptions)