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.
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);
div
container with the id
map-canvas
in the HTML page.
gem.control.StudioAddedDataControl()
is used to
add GeoJSON data previously saved in the online Map Studio.
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>
map-canvas
is the drawing area where the map is rendered.
The canvas is configured to fill the browser window.
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>
Adding free text search ¶
To add free-form text search functionality simply add the following JavaScript code:
1let searchControl = new gem.control.SearchControl({
2 searchPreferences: {
3 exactMatch: true,
4 maximumMatches: 3,
5 addressSearch: true,
6 mapPoisSearch: true,
7 setCursorReferencePoint: true
8 },
9 highlightOptions: {
10 contourColor: { r: 0, g: 255, b: 0, a: 0 }
11 }
12});
13defaultAppScreen.addControl(searchControl);
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:
JavaScriptHTML
SVG icon
Map style with stores data added in Studio
right-click on the links and select Save As.