Hello Maps
This complete example displays a movable and zoomable map, embedded inside an html element on a webpage.
Overview
The interactive map is centered on a desired initial location which is defined as a point using a (longitude, latitude) coordinate pair with altitude in meters. 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
- JavaScript
- HTML
// Start by setting your token from https://developer.magiclane.com/api/projects
gem.core.App.token="your_API_key_token";
The first step in JavaScript is to set your API key token gem.core.App.token
, which you can get at the Magic Lane website, see the Getting Started tutorial.
You only need to type your email address and create a new password.
let defaultAppScreen = gem.core.App.initAppScreen(
{
container: "canvasDiv",
center: [48.8612, 2.333, 1000]
}
);
<html>
<head>
<meta charset="utf-8" />
<title>Hello Map Example - MagicLane Maps SDK for JavaScript</title>
<link rel="stylesheet" type="text/css" href="https://www.magiclane.com/sdk/js/gem.css" />
</head>
<body>
<div id="canvasDiv" style="width: 100%; height: 100%; position: absolute;"></div>
<script type="text/javascript" src="https://www.magiclane.com/sdk/js/gemapi.js"></script>
<script type="text/javascript" src="token.js"></script>
<script type="text/javascript" src="jsHelloMapBasic.js"></script>
</body>
</html>
The canvas
is the drawing area where the map is rendered. The canvas is configured to fill the browser window.
Note that the div
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.
The example is 2 plain text files, one with the HTML code ( .html
file extension) and the other with the JavaScript code ( .js
file extension).
To run the example, the HTML file is loaded in a browser. The .js
file should be in the same directory, as it will be loaded automatically.
Source code for this example:
Right-click on the links and select Save As.
JavaScript Examples
Maps SDK for JavaScript Examples can be downloaded or cloned with Git.