Edit.Painting.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. L.Edit = L.Edit || {};
  2. L.Edit.Painting = L.Edit.SimpleShape.extend({
  3. _createMoveMarker: function () {
  4. var center = this._shape.getLatLng();
  5. this._moveMarker = this._createMarker(center, this.options.moveIcon);
  6. },
  7. _createResizeMarker: function () {
  8. var center = this._shape.getLatLng(),
  9. resizemarkerPoint = this._getResizeMarkerPoint(center);
  10. this._resizeMarkers = [];
  11. this._resizeMarkers.push(this._createMarker(resizemarkerPoint, this.options.resizeIcon));
  12. },
  13. _getResizeMarkerPoint: function (latlng) {
  14. // From L.shape.getBounds()
  15. var delta = this._shape._radius * Math.cos(Math.PI / 4),
  16. point = this._map.project(latlng);
  17. return this._map.unproject([point.x + delta, point.y - delta]);
  18. },
  19. _move: function (latlng) {
  20. var resizemarkerPoint = this._getResizeMarkerPoint(latlng);
  21. // Move the resize marker
  22. this._resizeMarkers[0].setLatLng(resizemarkerPoint);
  23. // Move the circle
  24. this._shape.setLatLng(latlng);
  25. },
  26. _resize: function (latlng) {
  27. var moveLatLng = this._moveMarker.getLatLng(),
  28. radius = moveLatLng.distanceTo(latlng);
  29. this._shape.setRadius(radius);
  30. }
  31. });