Skip to content

Store Locator using Studio Defined Data Source

This guide shows you how to build a store locator from scratch using store locations previously uploaded to the online Map Studio in GeoJSON format.

The finished example will look like this:

See the example fullscreen

When to use

  • The entire store location data set is relatively big.

  • The data set is changing frequently.

What is needed

  • Magic Lane API key token

  • Web server (an example is provided)

  • SVG file of the store logo (or use our sample SVG)

  • Store locations in GeoJSON format previously uploaded to the online Map Studio

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. In this project we use a local web server.

Adding stores data

 1// Start by setting your token from https://developer.magiclane.com/api/projects
 2if (gem.core.App.token === undefined)
 3     gem.core.App.token = "";
 4
 5let defaultAppScreen = gem.core.App.initAppScreen(
 6     {
 7             container: "map-canvas",
 8             center: [48.8562, 2.3516, 100000], // latitude , longitude, altitude
 9             style: "./BasicStyle_with_Paris_shops_ex.style" // map style downloaded from Studio that contains your data source
10     });
11
12let studioAddedControl = new gem.control.StudioAddedDataControl('954539838', '' /*default icon*/,
13     {
14             markerBubble: {
15                     title: ['name'],
16                     image: ['preview']
17             }
18     }
19);
20defaultAppScreen.addControl(studioAddedControl);
The map is rendered in the div container with the id map-canvas in the HTML page.
The map is centered on the specified position, given as latitude and longitude (in degrees) and altitude (in meters).
A map style is loaded.
See the Create a Map Style guide and the Custom Style Map guide to learn how to render a map with your custom style.
gem.control.StudioAddedDataControl() is used to add GeoJSON data previously saved in the online Map Studio.
The id of the dataset from the Map Studio is provided, along with the filename of an SVG logo to use for rendering the store locations on the map.
The store locations are added to the map: defaultAppScreen.addControl(studioAddedControl);
 1<!doctype html>
 2<html lang="en-us">
 3
 4<head>
 5    <meta charset="utf-8">
 6    <title>Using Studio Defined Data Example - MagicLane Maps SDK for JavaScript</title>
 7    <link rel="stylesheet" type="text/css" href="https://www.magiclane.com/sdk/js/gem.css">
 8</head>
 9
10<body>
11    <div id="map-canvas" style="width: 100%; height: 100%; position: absolute; overflow: hidden;">
12    </div>
13    <script src="https://www.magiclane.com/sdk/js/gemapi.js"></script>
14    <script type="text/javascript" src="token.js"></script>
15    <script type="text/javascript" src="jsStudioAddedData01.js"></script>
16</body>
17
18</html>
The map-canvas is the drawing area where the map is rendered. The canvas is configured to fill the browser window.
At the bottom, gemapi.js, the Maps SDK for JavaScript is loaded.
Next, the JavaScript source of this example is loaded.

Adding stores list

To display a list of the store locations add a menu list container to your HTML file and the following JavaScript code:

 1let listUIControl = new gem.control.ListControl({
 2     sourceControl: studioAddedControl,
 3       flyToItemAltitude: 250,
 4       container: 'menu-list-container',
 5       menuName: 'Store locations',
 6       titleProperties: ['name'],
 7       detailsProperties: ['kinds'],
 8       imageProperty: ['preview']
 9});
10defaultAppScreen.addControl(listUIControl);
1<div id="store-locator" style="width: 100%; height: 100%">
2 <div id="menu-list-container" class="menu-list-container" style="width: 30%; height: 100%; position: absolute;">
3 </div>
4 <div id="map-canvas" style="width: 70%; left: 30%; height: 100%; position:absolute; overflow:hidden"></div>
5</div>

Complete example code

 1// Start by setting your token from https://developer.magiclane.com/api/projects
 2if (gem.core.App.token === undefined)
 3     gem.core.App.token = "";
 4
 5let defaultAppScreen = gem.core.App.initAppScreen(
 6     {
 7             container: "map-canvas",
 8             center: [48.8562, 2.3516, 100000], // latitude , longitude, altitude
 9             style: "./BasicStyle_with_Paris_shops_ex.style" // map style downloaded from Studio that contains your data source
10     });
11
12let studioAddedControl = new gem.control.StudioAddedDataControl('954539838', '' /*default icon*/,
13     {
14             markerBubble: {
15                     title: ['name'],
16                     image: ['preview']
17             }
18     }
19);
20let listUIControl = new gem.control.ListControl({
21     sourceControl: studioAddedControl,
22     flyToItemAltitude: 250,
23     container: 'menu-list-container',
24     menuName: 'Store locations',
25     titleProperties: ['name'],
26     detailsProperties: ['kinds'],
27     imageProperty: ['preview']
28});
29defaultAppScreen.addControl(studioAddedControl);
30defaultAppScreen.addControl(listUIControl);
31
32let searchControl = new gem.control.SearchControl({
33     searchPreferences: {
34             exactMatch: true,
35             maximumMatches: 3,
36             addressSearch: true,
37             mapPoisSearch: true,
38             setCursorReferencePoint: true
39     },
40     highlightOptions: {
41             contourColor: { r: 0, g: 255, b: 0, a: 0 }
42     }
43});
44defaultAppScreen.addControl(searchControl);
 1<!doctype html>
 2<html lang="en-us">
 3
 4<head>
 5    <meta charset="utf-8">
 6    <title>Using Studio Defined Data Example - MagicLane Maps SDK for JavaScript</title>
 7    <link rel="stylesheet" type="text/css" href="https://www.magiclane.com/sdk/js/gem.css">
 8</head>
 9
10<body>
11    <div id="store-locator" style="width: 100%; height: 100%">
12        <div id="menu-list-container" style="width: 30%; height: 100%; position: absolute;"></div>
13        <div id="map-canvas" style="width: 70%; height: 100%; left: 30%; position: absolute; overflow: hidden;">
14        </div>
15    </div>
16    <script src="https://www.magiclane.com/sdk/js/gemapi.js"></script>
17    <script type="text/javascript" src="token.js"></script>
18    <script type="text/javascript" src="jsStudioAddedData03.js"></script>
19</body>
20
21</html>

Files

The finished example consists of the project directory containing 3 files:

  • JavaScript code (.js file extension)

  • HTML code (.html file extension)

  • SVG icon (.svg file extension)

To run the example, the HTML file is loaded in a browser.

Source code for this example:

JavaScript
HTML
SVG icon
Map style with stores data added in Studio

right-click on the links and select Save As.

JavaScript Examples

Maps SDK for JavaScript Examples can be downloaded or cloned with Git