diff --git a/bower.json b/bower.json index 8532a7a..344c820 100644 --- a/bower.json +++ b/bower.json @@ -10,7 +10,7 @@ "normalize-css": "*", "leaflet-search": "*", "leaflet-plugins": "*", - "leaflet-routing": "Turistforeningen/leaflet-routing#gh-pages", + "leaflet-routing": "nrenner/leaflet-routing#styles", "Leaflet.Elevation": "MrMufflon/Leaflet.Elevation#master", "async": "*" } diff --git a/bower_components/leaflet-routing/.bower.json b/bower_components/leaflet-routing/.bower.json index ba63fa6..48bf337 100644 --- a/bower_components/leaflet-routing/.bower.json +++ b/bower_components/leaflet-routing/.bower.json @@ -1,13 +1,13 @@ { "name": "leaflet-routing", - "homepage": "https://github.com/Turistforeningen/leaflet-routing", - "_release": "2cffb221af", + "homepage": "https://github.com/nrenner/leaflet-routing", + "_release": "ed9a880cb3", "_resolution": { "type": "branch", - "branch": "gh-pages", - "commit": "2cffb221af25cf624065b9c4d4cfdd299aea5746" + "branch": "styles", + "commit": "ed9a880cb353e1f2ef1c5de56bb2ac2758578663" }, - "_source": "git://github.com/Turistforeningen/leaflet-routing.git", - "_target": "gh-pages", - "_originalSource": "Turistforeningen/leaflet-routing" + "_source": "git://github.com/nrenner/leaflet-routing.git", + "_target": "styles", + "_originalSource": "nrenner/leaflet-routing" } \ No newline at end of file diff --git a/bower_components/leaflet-routing/CHANGELOG.md b/bower_components/leaflet-routing/CHANGELOG.md index 89444d6..44a84a1 100644 --- a/bower_components/leaflet-routing/CHANGELOG.md +++ b/bower_components/leaflet-routing/CHANGELOG.md @@ -7,9 +7,12 @@ Changelog * Add option for overriding draw shortcuts (#23) * Add option for disabling drawing marker (#18) +* Add options for tooltips (waypoint, segment) * Disable shortcuts by setting `options.shortcut` to `false`. * Add support for loading GeoJSON without waypoints (#16). * Add option to #loadGeoJSON() to disable map fit bounds. +* Add [OSM demo](http://turistforeningen.github.io/leaflet-routing/examples/osm.html) +* …as well as countless updates to the readme and code readability. **Breaking changes** diff --git a/bower_components/leaflet-routing/README.md b/bower_components/leaflet-routing/README.md index c759e18..dc8ae81 100644 --- a/bower_components/leaflet-routing/README.md +++ b/bower_components/leaflet-routing/README.md @@ -9,6 +9,11 @@ can be found ![Prototype Routing using Leaflet](https://raw.github.com/Turistforeningen/leaflet-routing/gh-pages/images/promo.gif) +## Features + +* Route handling interface for Leaflet +* Use your own routing backend, or OSM + ## Usage ```javascript @@ -17,6 +22,15 @@ var routing = new L.Routing({ ,routing: { router: myRouterFunction } + ,tooltips: { + waypoint: 'Waypoint. Drag to move; Click to remove.', + segment: 'Drag to create a new waypoint' + } + ,styles: { // see http://leafletjs.com/reference.html#polyline-options + trailer: {} // drawing line + ,track: {} // calculated route result + ,nodata: {} // line when no result (error) + } ,snapping: { layers: [mySnappingLayer] ,sensitivity: 15 @@ -106,16 +120,64 @@ routing.loadGeoJSON(geojson, [options], function(err) { }); ``` +## Events + +All events form Leaflet.Routing is prefixed with `routing:`. + +### Usage + +```javascript +routing.on('routing:someEvent', function() { + console.log('routing:someEvent triggered'); +}); +``` + +### L.Routing Events + +| Event name | Description | +|------------|-------------| +| `routing:draw-start` | Fired when drawing mode is started | +| `routing:draw-new` | Fired when drawing mode is started for a new route | +| `routing:draw-continue` | Fired when drawing mode is started for an existing route | +| `routing:draw-stop` | Fired when drawing mode ends | +| `routing:edit-start` | Fired when editing mode starts | +| `routing:edit-end` | Fired when editing mode ends | + +### Waypoint Events + +| Event name | Description | +|------------|-------------| +| `routing:routeWaypointStart` | Fired when a new or existing waypoint is created or moved | +| `routing:routeWaypointEnd` | Fired when routing is finished for new or moved waypoint | + +### Segment Events + +| Event name | Description | +|------------|-------------| +| `routing:rerouteAllSegmentsStart` | Fired when rerouting of all segments starts | +| `routing:rerouteAllSegmentsEnd` | Fired when rerouting of all segments completes | + ## Copyright Copyright (c) 2014, Den Norske Turistforening All rights reserved. -Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: +Redistribution and use in source and binary forms, with or without modification, are permitted +provided that the following conditions are met: -1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. -2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. +1. Redistributions of source code must retain the above copyright notice, this list of conditions + and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + and the following disclaimer in the documentation and/or other materials provided with the + distribution. -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF +THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/bower_components/leaflet-routing/src/L.Routing.Draw.js b/bower_components/leaflet-routing/src/L.Routing.Draw.js index 275a5c7..2d940e8 100644 --- a/bower_components/leaflet-routing/src/L.Routing.Draw.js +++ b/bower_components/leaflet-routing/src/L.Routing.Draw.js @@ -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); }); diff --git a/bower_components/leaflet-routing/src/L.Routing.Edit.js b/bower_components/leaflet-routing/src/L.Routing.Edit.js index a6733c3..918b226 100644 --- a/bower_components/leaflet-routing/src/L.Routing.Edit.js +++ b/bower_components/leaflet-routing/src/L.Routing.Edit.js @@ -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}); } } } diff --git a/bower_components/leaflet-routing/src/L.Routing.js b/bower_components/leaflet-routing/src/L.Routing.js index dc5fcd8..f49948f 100644 --- a/bower_components/leaflet-routing/src/L.Routing.js +++ b/bower_components/leaflet-routing/src/L.Routing.js @@ -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 ( l1, l2, 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); }); }