Route Ranges ¶
What is needed ¶
-
Magic Lane API key token
-
Web server (an example is provided)
Setup ¶
Get your Magic Lane API key token: if you do not have a token, see the Getting Started guide.
This project needs a web server. If you do not have access to a web server, you can easily install a local web server, see the Installing a Local Web Server guide.
Isochrones for Route Type Fastest ¶
The map supports pan and zoom, and is fully 3D, so holding down the shift key and panning will simultaneously rotate and tilt the map. If you want to jump right in, you can download the HTML file and the JavaScript file for this example in the same directory, and then load the HTML file in a web browser to try it out right now!
Or you can continue reading for a detailed explanation of the code.
How it works ¶
1// Start by setting your token from https://developer.magiclane.com/api/projects 2if (gem.core.App.token === undefined) gem.core.App.token = ''; 3 4let defaultAppScreen = gem.core.App.initAppScreen({ 5 container: "map-canvas", 6 center: [48.8612, 2.333, 7000000] // latitude , longitude, altitude 7}); 8 9let resultCb = function (routeResult) { 10} 11 12let defaultRoute = new gem.control.RouteControl({ 13 waypoints: [{ 14 latitude: 41.382991790771484, 15 longitude: 2.177398204803467, 16 altitude: 0, 17 bearing: 0.0 18 }, { 19 latitude: 41.383941650390625, 20 longitude: 2.1604349613189697, 21 altitude: 0, 22 bearing: 0.0 23 }], 24 preferences: { 25 buildTerrainProfile: false, 26 transportMode: gem.routesAndNavigation.ERouteTransportMode.ETM_Bicycle, 27 routeType: gem.routesAndNavigation.ERouteType.ERT_Fastest, 28 resultDetails: gem.routesAndNavigation.ERouteResultDetails.ERD_Full, 29 routeRanges: { 30 rangelist: [0, 60, 120, 240, 360], // measured in seconds for route type fastest 31 quality: 50 32 } 33 }, 34 resultCallback: resultCb 35}); 36defaultAppScreen.addControl(defaultRoute);The default view of the map is loaded:gem.core.App.initAppScreen();
Sample departure and destination coordinates are defined for the route usingwaypoints
.Altitude is in meters, and bearing(heading) is in degrees, where 0 is north, 90 is east, 180 is south and 270 (or -90) is west.Optionally, additional waypoints could be added between the departure and the destination, so the calculated route passes through those locations.Other route options are defined usingpreferences
through which we have set the transport mode to bicycle, the route type to fastest and the result details to full.The route ranges options are specified usingrouteRanges
and for the route type fastest the unit of measurement for therangeList
array items is seconds. The optionquality
can be adjusted to view higher or lower detailed route areas.The callback function which is called when the requested route computation completes can be defined usingresultCallback
.1<!doctype html> 2<html lang="en-us"> 3 4 <head> 5 <meta charset="utf-8"> 6 <meta name="viewport" content="width=device-width, initial-scale=1"> 7 <title>Route Ranges Controls - MagicLane Maps SDK for JavaScript</title> 8 <link rel="stylesheet" type="text/css" href="https://www.magiclane.com/sdk/js/gem.css"> 9 </head> 10 11 <body> 12 <div id="map-canvas" style="width:100%; height:100%; position:absolute"> 13 </div> 14 15 <script type="text/javascript" src="https://www.magiclane.com/sdk/js/gemapi.js"></script> 16 <script type="text/javascript" src="token.js"></script> 17 <script type="text/javascript" src="routeRangesControls01.js"></script> 18 </body> 19</html>Themap-canvas
divider is the drawing area where the map is rendered. The map canvas is configured to fill the entire page.Note that thediv
elements must be defined before loading the JavaScript source.At the bottom, gemapi.js, the Maps SDK for JavaScript is loaded.Next, the JavaScript source of this example is loaded.
.html
file extension) and the other with the
JavaScript code (
.js
file extension).
.js
file should be in the same directory, as it will be
loaded automatically.
Isochrones for Route Type Shortest ¶
If you want to jump right in, you can download the HTML file and the JavaScript file for this example in the same project directory, and then load the HTML file in a web browser to try it out right now!
Or you can continue reading for an explanation of the code.
How it works ¶
1// Start by setting your token from https://developer.magiclane.com/api/projects 2if (gem.core.App.token === undefined) gem.core.App.token = ''; 3 4let defaultAppScreen = gem.core.App.initAppScreen({ 5 container: "map-canvas", 6 center: [48.8612, 2.333, 7000000] // latitude , longitude, altitude 7}); 8 9let resultCb = function (routeResult) { 10} 11 12let defaultRoute = new gem.control.RouteControl({ 13 waypoints: [{ 14 latitude: 41.382991790771484, 15 longitude: 2.177398204803467, 16 altitude: 0, 17 bearing: 0.0 18 }, { 19 latitude: 41.383941650390625, 20 longitude: 2.1604349613189697, 21 altitude: 0, 22 bearing: 0.0 23 }], 24 preferences: { 25 buildTerrainProfile: false, 26 transportMode: gem.routesAndNavigation.ERouteTransportMode.ETM_Bicycle, 27 routeType: gem.routesAndNavigation.ERouteType.ERT_Shortest, 28 resultDetails: gem.routesAndNavigation.ERouteResultDetails.ERD_Full, 29 routeRanges: { 30 rangelist: [0, 100, 500, 1000, 2000], // measured in meters for route type shortest 31 quality: 75 32 } 33 }, 34 resultCallback: resultCb 35}); 36defaultAppScreen.addControl(defaultRoute);Route options are defined usingpreferences
through which we have set the transport mode to bicycle, the route type to shortest and the result details to full.The route ranges options are specified usingrouteRanges
and for the route type shortest the unit of measurement for therangeList
array items is meters. The optionquality
can be adjusted to view higher or lower detailed route areas.1<!doctype html> 2<html lang="en-us"> 3 4 <head> 5 <meta charset="utf-8"> 6 <meta name="viewport" content="width=device-width, initial-scale=1"> 7 <title>Route Ranges Controls - MagicLane Maps SDK for JavaScript</title> 8 <link rel="stylesheet" type="text/css" href="https://www.magiclane.com/sdk/js/gem.css"> 9 </head> 10 11 <body> 12 <div id="map-canvas" style="width:100%; height:100%; position:absolute"> 13 </div> 14 15 <script type="text/javascript" src="https://www.magiclane.com/sdk/js/gemapi.js"></script> 16 <script type="text/javascript" src="token.js"></script> 17 <script type="text/javascript" src="routeRangesControls02.js"></script> 18 </body> 19</html>
Isochrones for Route Type Economic ¶
If you want to jump right in, you can download the HTML file and the JavaScript file for this example in the same project directory, and then load the HTML file in a web browser to try it out right now!
Or you can continue reading for an explanation of the code.
How it works ¶
1// Start by setting your token from https://developer.magiclane.com/api/projects 2if (gem.core.App.token === undefined) gem.core.App.token = ''; 3 4let defaultAppScreen = gem.core.App.initAppScreen({ 5 container: "map-canvas", 6 center: [48.8612, 2.333, 7000000], // latitude , longitude, altitude 7}); 8 9let resultCb = function (routeResult) { 10} 11 12let defaultRoute = new gem.control.RouteControl({ 13 waypoints: [{ 14 latitude: 41.382991790771484, 15 longitude: 2.177398204803467, 16 altitude: 0, 17 bearing: 0.0 18 }, { 19 latitude: 41.383941650390625, 20 longitude: 2.1604349613189697, 21 altitude: 0, 22 bearing: 0.0 23 }], 24 preferences: { 25 buildTerrainProfile: false, 26 transportMode: gem.routesAndNavigation.ERouteTransportMode.ETM_Bicycle, 27 resultDetails: gem.routesAndNavigation.ERouteResultDetails.ERD_Full, 28 routeType: gem.routesAndNavigation.ERouteType.ERT_Economic, 29 bikeProfile: gem.routesAndNavigation.EBikeProfile.BP_City, 30 31 eBikeProfile: { 32 type: gem.routesAndNavigation.EEBikeType.EBP_PowerOnDemand, 33 bikeMass: 15.0, 34 bikerMass: 60.0, 35 auxConsumptionDay: 0.0, 36 auxConsumptionNight: 0.0 37 }, 38 39 routeRanges: { 40 rangelist: [0, 30, 60, 90, 150], // measured in watts per hour for route type economic 41 quality: 100 42 } 43 }, 44 resultCallback: resultCb 45}); 46defaultAppScreen.addControl(defaultRoute);Route options are defined usingpreferences
through which we have set the transport mode to bicycle, the bicycle type to city, the route type to economic and the result details to full.The route ranges options are specified usingrouteRanges
and for the route type economic the unit of measurement for therangeList
array items is watts per hour. The optionquality
can be adjusted to view higher or lower detailed route areas.Additional options can be specified for the bike profile through option objecteBikeProfile
such astype
,bikeMass
andbikerMass
(in kilograms),auxConsumptionDay
andauxConsumptionNight
(in watts).1<!doctype html> 2<html lang="en-us"> 3 4 <head> 5 <meta charset="utf-8"> 6 <meta name="viewport" content="width=device-width, initial-scale=1"> 7 <title>Route Ranges Controls - MagicLane Maps SDK for JavaScript</title> 8 <link rel="stylesheet" type="text/css" href="https://www.magiclane.com/sdk/js/gem.css"> 9 </head> 10 11 <body> 12 <div id="map-canvas" style="width:100%; height:100%; position:absolute"> 13 </div> 14 15 <script type="text/javascript" src="https://www.magiclane.com/sdk/js/gemapi.js"></script> 16 <script type="text/javascript" src="token.js"></script> 17 <script type="text/javascript" src="routeRangesControls03.js"></script> 18 </body> 19</html>
Source Code for the Examples ¶
-
Isochrones for route type fastest:
index01.html and routeRangesControls01.js -
Isochrones for route type shortest:
index02.html and routeRangesControls02.js -
Isochrones for route type economic:
index03.html and routeRangesControls03.js
Right-click on the links and select Save As.