commit 06eb0b8bc36bf5b753c748992c16b26a81ca9266
parent 9ea8492a0893faf8f59add52a6fb1415fe646215
Author: Sergej Orlov <wladimirych@gmail.com>
Date: Fri, 24 Mar 2017 12:35:44 +0300
[azimuth] calc sampling interval for profile; hide/show handling
Diffstat:
1 file changed, 33 insertions(+), 8 deletions(-)
diff --git a/src/lib/leaflet.control.azimuth/index.js b/src/lib/leaflet.control.azimuth/index.js
@@ -10,7 +10,7 @@ import 'leaflet-rotatedmarker';
import iconPointer from './pointer.svg';
import iconPointerStart from './pointer-start.svg';
import iconPointerEnd from './pointer-end.svg';
-import 'lib/leaflet.control.elevation-profile';
+import {ElevationProfile, calcSamplingInterval} from 'lib/leaflet.control.elevation-profile';
function radians(x) {
return x / 180 * Math.PI;
@@ -70,10 +70,12 @@ L.Control.Azimuth = L.Control.extend({
.on('click', L.DomEvent.stopPropagation),
start: L.marker([0, 0], {icon: iconStart, draggable: true, which: 'start', rotationOrigin: 'center center'})
.on('drag', this.onMarkerDrag, this)
- .on('click', L.DomEvent.stopPropagation),
+ .on('click', L.DomEvent.stopPropagation)
+ .on('dragend', this.onMarkerDragEnd, this),
end: L.marker([0, 0], {icon: iconEnd, draggable: true, which: 'end', rotationOrigin: 'center center'})
.on('drag', this.onMarkerDrag, this)
.on('click', L.DomEvent.stopPropagation)
+ .on('dragend', this.onMarkerDragEnd, this)
};
this.azimuthLine = L.polyline([], {interactive: false, weight: 1.5});
},
@@ -103,6 +105,12 @@ L.Control.Azimuth = L.Control.extend({
this.setPoints({[marker.options.which]: marker.getLatLng()});
},
+ onMarkerDragEnd: function() {
+ if (this.elevationControl) {
+ this.showProfile();
+ }
+ },
+
setEnabled: function(enabled) {
if (!!enabled === this.isEnabled()) {
return;
@@ -116,8 +124,8 @@ L.Control.Azimuth = L.Control.extend({
L.DomUtil.removeClass(this._map._container, 'azimuth-control-active');
this._map.off('click', this.onMapClick, this);
this.setPoints({start: null, end: null});
+ this.hideProfile();
}
-
},
isEnabled: function() {
@@ -181,19 +189,36 @@ L.Control.Azimuth = L.Control.extend({
} else if (this.points.start && !this.points.end) {
this.setPoints({end: e.latlng})
} else if (this.points.start && this.points.end) {
+ this.hideProfile();
this.setPoints({start: e.latlng, end: null})
}
},
- onProfileButtonClick: function() {
+ showProfile: function() {
+ if (!this.points.end) {
+ return;
+ }
if (this.elevationControl) {
this.elevationControl.removeFrom(this._map);
}
- this.elevationControl = new L.Control.ElevationProfile(this._map, [this.points.start, this.points.end ], {
- samplingInterval: 100
- }
- );
+ const dist = this.points.start.distanceTo(this.points.end);
+ this.elevationControl = new ElevationProfile(this._map, [this.points.start, this.points.end], {
+ samplingInterval: calcSamplingInterval(dist)
+ });
+ this.elevationControl.on('remove', () => this.elevationControl = null);
+
+ },
+
+ hideProfile: function() {
+ if (this.elevationControl) {
+ this.elevationControl.removeFrom(this._map);
+ }
+ this.elevationControl = null;
+ },
+
+ onProfileButtonClick: function() {
+ this.showProfile();
}
}