switch leaflet-routing to development fork

This commit is contained in:
Norbert Renner 2014-08-23 20:33:00 +02:00
parent 8344404483
commit 30cbcc6f6d
7 changed files with 137 additions and 42 deletions

View file

@ -90,8 +90,6 @@ L.Routing.Draw = L.Handler.extend({
* @access private
*
* @return void
*
* @todo hide and style the trailer!
*/
,_addHooks: function() {
if (!this._map) { return; }
@ -109,10 +107,12 @@ L.Routing.Draw = L.Handler.extend({
// Trailing line
if (!this._trailer) {
var ll = this._map.getCenter();
this._trailer = new L.Polyline([ll, ll], {
opacity: 0.2
this._trailerOpacity = this.options.styles.trailer.opacity || 0.2;
var style = L.extend({}, this.options.styles.trailer, {
opacity: 0.0
,clickable: false
});
this._trailer = new L.Polyline([ll, ll], style);
}
this._parent.on('waypoint:mouseover', this._catchWaypointEvent, this);
@ -226,7 +226,29 @@ L.Routing.Draw = L.Handler.extend({
,_show: function() {
this._hidden = false;
this._marker.setOpacity(this.options.icons.draw ? 1.0 : 0.0);
this._trailer.setStyle({opacity: 0.2});
this._showTrailer();
}
/**
* Show trailer when hidden
*
* @access private
*
* @return void
*/
,_showTrailer: function() {
if (this._trailer.options.opacity === 0.0) {
this._trailer.setStyle({opacity: this._trailerOpacity});
}
}
/**
* Set trailing guide line
*
*/
,_setTrailer: function(fromLatLng, toLatLng) {
this._trailer.setLatLngs([fromLatLng, toLatLng]);
this._showTrailer();
}
/**
@ -252,7 +274,7 @@ L.Routing.Draw = L.Handler.extend({
if (last !== null) {
this._trailer.setLatLngs([last.getLatLng(), latlng]);
this._setTrailer(last.getLatLng(), latlng);
};
}
@ -276,10 +298,10 @@ L.Routing.Draw = L.Handler.extend({
if (this.options.snapping) {
latlng = L.LineUtil.snapToLayers(latlng, null, this.options.snapping);
}
marker = new L.Marker(latlng);
marker = new L.Marker(latlng, {title: this.options.tooltips.waypoint });
last = this._parent.getLast();
this._trailer.setLatLngs([latlng, latlng]);
this._setTrailer(latlng, latlng);
this._parent.addWaypoint(marker, last, null, function(err, data) {
// console.log(err, data);
});

View file

@ -94,7 +94,7 @@ L.Routing.Edit = L.Handler.extend({
if (!this._map) { return; }
if (!this._mouseMarker) {
this._mouseMarker = L.marker(this._map.getCenter(), {
this._mouseMarker = new L.Marker(this._map.getCenter(), {
icon: L.divIcon({
className: 'line-mouse-marker'
,iconAnchor: [5, 5]
@ -104,13 +104,15 @@ L.Routing.Edit = L.Handler.extend({
,draggable: true
,opacity: 0
,zIndexOffset: this.options.zIndexOffset
,title: this.options.tooltips.segment
});
}
this._mouseMarker.addTo(this._map);
if (!this._trailer1) {
var ll = this._map.getCenter();
var style = {opacity: 0.0,clickable: false};
this._trailerOpacity = this.options.styles.trailer.opacity || 0.2;
var style = L.extend({}, this.options.styles.trailer, {opacity: 0.0,clickable: false});
this._trailer1 = new L.Polyline([ll, ll], style);
this._trailer2 = new L.Polyline([ll, ll], style);
}
@ -369,10 +371,10 @@ L.Routing.Edit = L.Handler.extend({
return;
} else {
if (next !== null) {
this._trailer1.setStyle({opacity: 0.2});
this._trailer1.setStyle({opacity: this._trailerOpacity});
}
if (prev !== null) {
this._trailer2.setStyle({opacity: 0.2});
this._trailer2.setStyle({opacity: this._trailerOpacity});
}
}
}

View file

@ -23,12 +23,21 @@ L.Routing = L.Control.extend({
// OPTIONS
,options: {
position: 'topleft'
,tooltips: {
waypoint: 'Waypoint. Drag to move; Click to remove.',
segment: 'Drag to create a new waypoint'
}
,icons: {
start: new L.Icon.Default()
,end: new L.Icon.Default()
,normal: new L.Icon.Default()
,draw: new L.Icon.Default()
}
,styles: {
trailer: {}
,track: {}
,nodata: {}
}
,zIndexOffset: 2000
,routing: {
router: null // function (<L.Latlng> l1, <L.Latlng> l2, <Function> cb)
@ -91,17 +100,8 @@ L.Routing = L.Control.extend({
L.DomEvent.addListener(this._container, 'keyup', this._keyupListener, this);
}
this._draw = new L.Routing.Draw(this, {
icons: this.options.icons
,zIndexOffset: this.options.zIndexOffset
,snapping: this.options.snapping
});
this._edit = new L.Routing.Edit(this, {
icons: this.options.icons
,zIndexOffset: this.options.zIndexOffset
,snapping: this.options.snapping
});
this._draw = new L.Routing.Draw(this, this.options);
this._edit = new L.Routing.Edit(this, this.options);
this._edit.enable();
this.on('waypoint:click', this._waypointClickHandler, this)
@ -175,7 +175,7 @@ L.Routing = L.Control.extend({
*/
,addWaypoint: function(marker, prev, next, cb) {
if (marker instanceof L.LatLng) {
marker = new L.Marker(marker);
marker = new L.Marker(marker, { title: this.options.tooltips.waypoint });
}
marker._routing = {
@ -297,12 +297,14 @@ L.Routing = L.Control.extend({
*/
,routeWaypoint: function(marker, cb) {
var i = 0;
var firstErr;
var $this = this;
var callback = function(err, data) {
i++;
firstErr = firstErr || err;
if (i === 2) {
$this.fire('routing:routeWaypointEnd');
cb(err, marker);
$this.fire('routing:routeWaypointEnd', { err: firstErr });
cb(firstErr, marker);
}
}
@ -326,14 +328,16 @@ L.Routing = L.Control.extend({
,rerouteAllSegments: function(cb) {
var numSegments = this.getWaypoints().length - 1;
var callbackCount = 0;
var firstErr;
var $this = this;
var callback = function(err, data) {
callbackCount++;
firstErr = firstErr || err;
if (callbackCount >= numSegments) {
$this.fire('routing:rerouteAllSegmentsEnd');
$this.fire('routing:rerouteAllSegmentsEnd', { err: firstErr });
if (cb) {
cb(err);
cb(firstErr);
}
}
};
@ -371,7 +375,9 @@ L.Routing = L.Control.extend({
this._router(m1.getLatLng(), m2.getLatLng(), function(err, layer) {
if (typeof layer === 'undefined') {
var layer = new L.Polyline([m1.getLatLng(), m2.getLatLng()]);
var layer = new L.Polyline([m1.getLatLng(), m2.getLatLng()], $this.options.styles.nodata);
} else {
layer.setStyle($this.options.styles.track);
}
layer._routing = {
@ -387,7 +393,7 @@ L.Routing = L.Control.extend({
m1._routing.nextLine = layer;
m2._routing.prevLine = layer;
return cb(null, layer);
return cb(err, layer);
});
}