diff --git a/.gitignore b/.gitignore index 57c0bdc..1acc10c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ bower_components/leaflet-routing/libs/ +bower_components/leaflet-routing/examples/ bower_components/Leaflet.Elevation/* !bower_components/Leaflet.Elevation/dist/ !bower_components/Leaflet.Elevation/src/ diff --git a/bower_components/leaflet-routing/.bower.json b/bower_components/leaflet-routing/.bower.json index df1ed87..ba63fa6 100644 --- a/bower_components/leaflet-routing/.bower.json +++ b/bower_components/leaflet-routing/.bower.json @@ -1,11 +1,11 @@ { "name": "leaflet-routing", "homepage": "https://github.com/Turistforeningen/leaflet-routing", - "_release": "f78c22ed00", + "_release": "2cffb221af", "_resolution": { "type": "branch", "branch": "gh-pages", - "commit": "f78c22ed001788761b81172ef746a357a92e2f5f" + "commit": "2cffb221af25cf624065b9c4d4cfdd299aea5746" }, "_source": "git://github.com/Turistforeningen/leaflet-routing.git", "_target": "gh-pages", diff --git a/bower_components/leaflet-routing/CHANGELOG.md b/bower_components/leaflet-routing/CHANGELOG.md new file mode 100644 index 0000000..89444d6 --- /dev/null +++ b/bower_components/leaflet-routing/CHANGELOG.md @@ -0,0 +1,38 @@ +Changelog +========= + +### 0.2.0 (Unreadlesed) + +**Features** + +* Add option for overriding draw shortcuts (#23) +* Add option for disabling drawing marker (#18) +* 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. + +**Breaking changes** + +* Default shortcut key for draw enable is `d` +* Default shortcut key for draw disable is `q` + +### 0.1.1 March 11, 2014 + +**Features** + +* Add changelog overview (#14) +* Add Change map bounds when loading GeoJSON (#13) + +**Bugfixes** + +* Fix undefined evaluation when snapping layer is not avaiable (#15) +* Fail gracefully when loading invalid GeoJSON (#12) + +### 0.1.0 March 10, 2014 + +* Implements `#loadGeoJSON()` method (#3) + +#### Backwards compability note + +* Format of `properties.waypoints` in `#toGeoJSON()` is changed according to #3. + diff --git a/bower_components/leaflet-routing/LICENSE b/bower_components/leaflet-routing/LICENSE index aee5fdd..c01d507 100644 --- a/bower_components/leaflet-routing/LICENSE +++ b/bower_components/leaflet-routing/LICENSE @@ -1,22 +1,22 @@ -Copyright (c) 2013, Turistforeningen, Hans Kristian Flaatten +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 + 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. + 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. \ No newline at end of file +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/README.md b/bower_components/leaflet-routing/README.md index 83e95e8..c759e18 100644 --- a/bower_components/leaflet-routing/README.md +++ b/bower_components/leaflet-routing/README.md @@ -1,7 +1,11 @@ -Routing in Leaflet -================== +Leaflet.Routing +=============== -Research and development of a Leaflet.js routing module. The module will be capable of the routing markers and returning geojson in various ways. +Leaflet.Routing is a routing controller for the popular Leaflet mapping +framework. The module provides an intuitive interface for routing paths between +waypoints using any user specified routing service. A demo using the OSM data +can be found +[here](http://turistforeningen.github.io/leaflet-routing/examples/osm.html). ![Prototype Routing using Leaflet](https://raw.github.com/Turistforeningen/leaflet-routing/gh-pages/images/promo.gif) @@ -11,13 +15,19 @@ Research and development of a Leaflet.js routing module. The module will be capa var routing = new L.Routing({ position: 'topright' ,routing: { - router: myRouter + router: myRouterFunction } ,snapping: { - layers: [snapping] + layers: [mySnappingLayer] ,sensitivity: 15 ,vertexonly: false } + ,shortcut: { + draw: { + enable: 68 // 'd' + ,disable: 81 // 'q' + } + } }); map.addControl(routing); ``` @@ -35,11 +45,13 @@ routing.routing(true); ``` ### Enable Snapping `NOT IMPLEMETED` + ```javascript routing.snapping(true); ``` ### Recalculate the complete route by routing each segment + ```javascript routing.rerouteAllSegments(callback); ``` @@ -51,29 +63,52 @@ var first = routing.getFirst(); ``` ### Get last waypoint + ```javascript var last = routing.getLast(); ``` ### Get all waypoints + ```javascript var waypointsArray = routing.getWaypoints(); ``` ### Routing to Polyline + ```javascript var polyline = routing.toPolyline(); ``` ### To GeoJSON + ```javascript var geoJSON3D = routing.toGeoJSON(); var geoJSON2D = routing.toGeoJSON(false); ``` +### Load GeoJSON + +Load GeoJSON with and without `properties.waypoints`. + +#### Options + +* `number` waypointDistance - distance between inserted waypoints for GeoJSON without waypoints. +* `boolean` fitBounds - fit map arround loaded GeoJSON. + +```javascript +routing.loadGeoJSON(geojson, [options], function(err) { + if (err) { + console.log(err); + } else { + console.log('Finished loading GeoJSON'); + } +}); +``` + ## Copyright -Copyright (c) 2013, Turistforeningen +Copyright (c) 2014, Den Norske Turistforening All rights reserved. @@ -83,3 +118,4 @@ Redistribution and use in source and binary forms, with or without modification, 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. + diff --git a/bower_components/leaflet-routing/app.js b/bower_components/leaflet-routing/app.js index 3a335f9..1b3efce 100644 --- a/bower_components/leaflet-routing/app.js +++ b/bower_components/leaflet-routing/app.js @@ -141,7 +141,7 @@ var routing, data; var coords = routing.toGeoJSON().coordinates; var data = []; for (var i = 0; i < coords.length; i++) { - data.push(coords[i][1] + ' ' + coords[i][0]); + data.push(coords[i][0] + ' ' + coords[i][1]); } data = 'LINESTRING(' + data.join(',') + ')'; $.post('http://mintur.ut.no/lib/ajax/post_geom.php?api_key=' + apiKey + '&tp_id=' + id, {coords: data}, function(data) { diff --git a/bower_components/leaflet-routing/index.html b/bower_components/leaflet-routing/index.html index e6b1dcc..136e383 100644 --- a/bower_components/leaflet-routing/index.html +++ b/bower_components/leaflet-routing/index.html @@ -38,7 +38,7 @@ - + diff --git a/bower_components/leaflet-routing/src/L.Routing.Draw.js b/bower_components/leaflet-routing/src/L.Routing.Draw.js index 38f5289..275a5c7 100644 --- a/bower_components/leaflet-routing/src/L.Routing.Draw.js +++ b/bower_components/leaflet-routing/src/L.Routing.Draw.js @@ -99,7 +99,8 @@ L.Routing.Draw = L.Handler.extend({ // Visible Marker if (!this._marker) { this._marker = new L.Marker(this._map.getCenter(), { - icon: this.options.icons.normal + icon: (this.options.icons.draw ? this.options.icons.draw : new L.Icon.Default()) + ,opacity: (this.options.icons.draw ? 1.0 : 0.0) ,zIndexOffset: this.options.zIndexOffset ,clickable: false }); @@ -224,7 +225,7 @@ L.Routing.Draw = L.Handler.extend({ */ ,_show: function() { this._hidden = false; - this._marker.setOpacity(1.0); + this._marker.setOpacity(this.options.icons.draw ? 1.0 : 0.0); this._trailer.setStyle({opacity: 0.2}); } diff --git a/bower_components/leaflet-routing/src/L.Routing.js b/bower_components/leaflet-routing/src/L.Routing.js index 1f8a6d5..dc5fcd8 100644 --- a/bower_components/leaflet-routing/src/L.Routing.js +++ b/bower_components/leaflet-routing/src/L.Routing.js @@ -17,7 +17,7 @@ L.Routing = L.Control.extend({ // CONSTANTS ,statics: { - VERSION: '0.0.2-dev' + VERSION: '0.1.1-dev' } // OPTIONS @@ -27,6 +27,7 @@ L.Routing = L.Control.extend({ start: new L.Icon.Default() ,end: new L.Icon.Default() ,normal: new L.Icon.Default() + ,draw: new L.Icon.Default() } ,zIndexOffset: 2000 ,routing: { @@ -37,6 +38,12 @@ L.Routing = L.Control.extend({ ,sensitivity: 10 // snapping sensitivity ,vertexonly: false // vertex only snapping } + ,shortcut: { + draw: { + enable: 68, // char code for 'd' + disable: 81 // char code for 'q' + } + } } /** @@ -79,7 +86,10 @@ L.Routing = L.Control.extend({ //L.DomUtil.disableTextSelection(); //this._tooltip = new L.Tooltip(this._map); //this._tooltip.updateContent({ text: L.drawLocal.draw.marker.tooltip.start }); - L.DomEvent.addListener(this._container, 'keyup', this._keyupListener, this); + + if (this.options.shortcut) { + L.DomEvent.addListener(this._container, 'keyup', this._keyupListener, this); + } this._draw = new L.Routing.Draw(this, { icons: this.options.icons @@ -138,9 +148,16 @@ L.Routing = L.Control.extend({ delete this.options; } + /** + * Called whenever a waypoint is clicked + * + * @access private + * + * @param e - click event + */ ,_waypointClickHandler: function(e) { this.removeWaypoint(e.marker, function() { - console.log(arguments); + // console.log(arguments); }); } @@ -152,7 +169,7 @@ L.Routing = L.Control.extend({ * @param marker - new waypoint marker (can be ll) * @param prev - previous waypoint marker * @param next - next waypoint marker - * @param cb - callback method + * @param cb - callback method (err, marker) * * @return void */ @@ -501,27 +518,134 @@ L.Routing = L.Control.extend({ if (current === null) { return geojson; } - geojson.properties.waypoints.push([current.getLatLng().lng, current.getLatLng().lat]); + // First waypoint marker + geojson.properties.waypoints.push({ + coordinates: [current.getLatLng().lng, current.getLatLng().lat], + _index: 0 + }); while (current._routing.nextMarker) { - var next = current._routing.nextMarker - geojson.properties.waypoints.push([next.getLatLng().lng, next.getLatLng().lat]); + var next = current._routing.nextMarker; + // Line segment var tmp = current._routing.nextLine.getLatLngs(); for (var i = 0; i < tmp.length; i++) { if (tmp[i].alt && (typeof enforce2d === 'undefined' || enforce2d === false)) { - geojson.coordinates.push([tmp[i].lat, tmp[i].lng, tmp[i].alt]); + geojson.coordinates.push([tmp[i].lng, tmp[i].lat, tmp[i].alt]); } else { - geojson.coordinates.push([tmp[i].lat, tmp[i].lng]); + geojson.coordinates.push([tmp[i].lng, tmp[i].lat]); } } + // Waypoint marker + geojson.properties.waypoints.push({ + coordinates: [next.getLatLng().lng, next.getLatLng().lat], + _index: geojson.coordinates.length-1 + }); + + // Next waypoint marker current = current._routing.nextMarker; } return geojson } + /** + * Import route from GeoJSON + * + * @access public + * + * @param geojson - GeoJSON object with waypoints + * @param opts - parsing options + * @param cb - callback method (err) + * + * @return undefined + * + */ + ,loadGeoJSON: function(geojson, opts, cb) { + var $this, oldRouter, index, waypoints; + + $this = this; + + // Check for optional options parameter + if (typeof opts === 'function' || typeof opts === 'undefined') { + cb = opts; + opts = {} + } + + // Set default options + opts.waypointDistance = opts.waypointDistance || 50; + opts.fitBounds = opts.fitBounds || true; + + // Check for waypoints before processing geojson + if (!geojson.properties || !geojson.properties.waypoints) { + if (!geojson.properties) { geojson.properties = {} }; + geojson.properties.waypoints = []; + + for (var i = 0; i < geojson.coordinates.length; i = i + opts.waypointDistance) { + geojson.properties.waypoints.push({ + _index: i, + coordinates: geojson.coordinates[i].slice(0, 2) + }); + } + + if (i > geojson.coordinates.length-1) { + geojson.properties.waypoints.push({ + _index: geojson.coordinates.length-1, + coordinates: geojson.coordinates[geojson.coordinates.length-1].slice(0, 2) + }); + } + } + + index = 0; + oldRouter = $this._router; + waypoints = geojson.properties.waypoints; + + // This is a fake router. + // + // It is currently not possible to add a waypoint with a known line segment + // manually. We are hijacking the router so that we can intercept the + // request and return the correct linesegment. + // + // It you want to fix this; please make a patch and submit a pull request on + // GitHub. + $this._router = function(m1, m2, cb) { var start = + waypoints[index-1]._index; var end = waypoints[index]._index+1; + + return cb(null, L.GeoJSON.geometryToLayer({ + type: 'LineString', + coordinates: geojson.coordinates.slice(start, end) + })); + }; + + // Clean up + end = function() { + $this._router = oldRouter; // Restore router + // Set map bounds based on loaded geometry + setTimeout(function() { + if (opts.fitBounds) { + $this._map.fitBounds(L.polyline(L.GeoJSON.coordsToLatLngs(geojson.coordinates)).getBounds()); + } + + if (typeof cb === 'function') { cb(null); } + }, 0); + } + + // Add waypoints + add = function() { + if (!waypoints[index]) { return end() } + + var coords = waypoints[index].coordinates; + var prev = $this._waypoints._last; + + $this.addWaypoint(L.latLng(coords[1], coords[0]), prev, null, function(err, m) { + add(++index); + }); + } + + add(); + } + /** * Start (or continue) drawing * @@ -583,9 +707,9 @@ L.Routing = L.Control.extend({ * @return void */ ,_keyupListener: function (e) { - if (e.keyCode === 27) { + if (e.keyCode === this.options.shortcut.draw.disable) { this._draw.disable(); - } else if (e.keyCode === 77) { + } else if (e.keyCode === this.options.shortcut.draw.enable) { this._draw.enable(); } } diff --git a/bower_components/leaflet-routing/src/utils/LineUtil.Snapping.js b/bower_components/leaflet-routing/src/utils/LineUtil.Snapping.js index dfa41c7..b621a45 100644 --- a/bower_components/leaflet-routing/src/utils/LineUtil.Snapping.js +++ b/bower_components/leaflet-routing/src/utils/LineUtil.Snapping.js @@ -18,6 +18,11 @@ L.Util.extend(L.LineUtil, { minDist = Infinity; minPoint = latlng; minPoint._feature = null; // containing layer + + if (!opts || !opts.layers || !opts.layers.length) { + return minPoint; + } + map = opts.layers[0]._map; // @todo check for undef for (i = 0; i < opts.layers.length; i++) {