Comments (4)
Hi!
Mapzen's tutorial is mainly to spin up lrm-mapzen UI on the map. (and also, it is outdated! thanks for letting us be aware of that! we will update the page soon!)
but lrm-mapzen also lets you access to the response through callback. This behavior is documented on Leaflet Routing Machine docs.
so code snippet is going to be like this
// Create a map. Targets div with id 'map'.
var map = L.map('map');
var layer = Tangram.leafletLayer({
scene: 'https://mapzen.com/carto/refill-style/refill-style.zip',
attribution: '<a href="https://mapzen.com/tangram" target="_blank">Tangram</a> | <a href="http://www.openstreetmap.org/about" target="_blank">© OSM contributors | <a href="https://mapzen.com/" target="_blank">Mapzen</a>',
}); // End of layer.
// Add's the styles and attributions to the map.
layer.addTo(map);
var sampleLatLngs = [L.Routing.waypoint(L.latLng(51.4998,-2.5468)), L.Routing.waypoint(L.latLng(51.5055,-2.5603))];
// You can grab free api key at https://mapzen.com/developers
var router = L.Routing.mapzen('your-api-key', {costing: 'pedestrian'});
// We are just going to print out route turned from the server
var sampleFunction = function(err, routes) {
// Check your browser console
console.log(routes);
}
router.route(sampleLatLngs, sampleFunction);
If you check your browser, you will see the response from the server. instructions
property probably has the info you want. (instruction, maneuver type) . (Mind that you are going to need your own api key. Also the code snippet above is not going to show anything other than console since we didn't set the view of the map) !
I hope it helps!
from lrm-mapzen.
That's perfect, got it now! I can't thank you enough for putting so much time into helping me with this issue @hanbyul-here!
from lrm-mapzen.
Hi!
Thank you very much! That's what I was looking for. Do you know if there's a function that simplifies those routes as just (left, right, straight)? Either way that's already really good for what we are trying to achieve.
Thanks again @hanbyul-here, your explanation is very helpful!
from lrm-mapzen.
@csalmeida There is no function helping it, but parsing routes
is pretty straightforward.
Also, notice that our response has various types of instruction go to type part of the docs and check how many maneuver types are there!
You can access to this type number through instructions
property like this.
for ( var i = 0; i < routes[0].instructions.length; i++) {
// Getting maneuver type from instruction
var maneuverType = routes[0].instructions[i].type;
console.log(maneuverType);
}
Then you can generate some instructions like left, sharp left with maneuverType
variable's value.
from lrm-mapzen.
Related Issues (20)
- Example of bicycle routing with different types of bikes
- Sub-Route (transfer) bug HOT 1
- getting ready for leaflet 1.0 HOT 2
- add location hash for gh-pages example
- Error in Routing Calculations HOT 4
- Problem with pedestrian mode HOT 4
- Tune by Turn & Search for the destination HOT 3
- L.Routing.mapzenFormatter and options HOT 1
- Can't set the language to spanish HOT 8
- No 'Access-Control-Allow-Origin' to valhalla.mapzen.com HOT 7
- How to get a route without using the control? HOT 4
- Consider how to handle routing with multiple break points where some are along the way HOT 2
- Making the turn by turn example work with requirejs (r.js) HOT 2
- add a buffer to fitSelectedRoutes so pins don't get cut off HOT 1
- change too general class name HOT 1
- not passing some options HOT 1
- make default pins for the start and end of a route different colors
- fitBounds doesn't work with mapzenLine
- Add possibility to use your own Valhalla Server
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lrm-mapzen.