-
Notifications
You must be signed in to change notification settings - Fork 455
/
Copy pathSimple data layer options.html
264 lines (221 loc) · 10.4 KB
/
Simple data layer options.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
<!DOCTYPE html>
<html lang="en">
<head>
<title>Simple data layer options - Azure Maps Web SDK Samples</title>
<meta charset="utf-8" />
<link rel="shortcut icon" href="/favicon.ico"/>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<meta name="description" content="This sample shows how the different options of the simple data layer affect rendering." />
<meta name="keywords" content="Microsoft maps, map, gis, API, SDK, line, linestring, polyline, layer, linelayer, symbols, markers, pins, pushpins, spatial data, spatial io module" />
<meta name="author" content="Microsoft Azure Maps" /><meta name="version" content="1.0" />
<meta name="screenshot" content="screenshot.jpg" />
<!-- Add references to the Azure Maps Map control JavaScript and CSS files. -->
<link href="https://atlas.microsoft.com/sdk/javascript/mapcontrol/3/atlas.min.css" rel="stylesheet" />
<script src="https://atlas.microsoft.com/sdk/javascript/mapcontrol/3/atlas.min.js"></script>
<!-- Add reference to the Azure Maps Spatial IO module. -->
<script src="https://atlas.microsoft.com/sdk/javascript/spatial/0/atlas-spatial.min.js"></script>
<script src="/lib/clipboard/dist/clipboard.min.js"></script>
<script>
var map, datasource, layer, defaultOptions, removeDefaults;
function getMap() {
//Initialize a map instance.
map = new atlas.Map('myMap', {
center: [-90, 40],
zoom: 2,
pitch: 20,
view: 'Auto',
//Add authentication details for connecting to Azure Maps.
authOptions: {
//Use Microsoft Entra ID authentication.
authType: 'anonymous',
clientId: 'e6b6ab59-eb5d-4d25-aa57-581135b927f0', //Your Azure Maps client id for accessing your Azure Maps account.
getToken: function (resolve, reject, map) {
//URL to your authentication service that retrieves an Microsoft Entra ID Token.
var tokenServiceUrl = 'https://samples.azuremaps.com/api/GetAzureMapsToken';
fetch(tokenServiceUrl).then(r => r.text()).then(token => resolve(token));
}
//Alternatively, use an Azure Maps key. Get an Azure Maps key at https://azure.com/maps. NOTE: The primary key should be used as the key.
//authType: 'subscriptionKey',
//subscriptionKey: '[YOUR_AZURE_MAPS_KEY]'
}
});
//Wait until the map resources are ready.
map.events.add('ready', function () {
//Create a style control and add it to the map.
map.controls.add([
new atlas.control.StyleControl({
style: 'dark',
mapStyles: 'all'
}),
new atlas.control.PitchControl({
style: 'dark'
})
], {
position: 'top-right'
});
//Create a data source and add it to the map.
datasource = new atlas.source.DataSource();
map.sources.add(datasource);
//Add a simple data layer for rendering the data.
layer = new atlas.layer.SimpleDataLayer(datasource);
map.layers.add(layer);
//Load an initial data set.
loadDataSet('/data/Kml/internet_users_2005_choropleth_3D.kml');
defaultOptions = layer.getOptions();
//Update the layer with the options in the input fields.
updateLayer();
});
new ClipboardJS('.copyBtn');
}
function loadDataSet(url) {
//Read the spatial data and add it to the map.
atlas.io.read(url).then(r => {
if (r) {
//Update the features in the data source.
datasource.setShapes(r);
//If bounding box information is known for data, set the map view to it.
if (r.bbox) {
map.setCamera({ bounds: r.bbox, padding: 50 });
}
}
});
}
function updateLayer() {
var options = getInputOptions();
//Update all the options in the layer.
layer.setOptions(options);
document.getElementById('CodeOutput').value = JSON.stringify(options, null, '\t').replace(/\"([^(\")"]+)\":/g, "$1:");
}
function getInputOptions() {
removeDefaults = document.getElementById('RemoveDefaults').checked;
layer.closePopup();
return {
allowExtrusions: getPropertyValue('allowExtrusions', document.getElementById('allowExtrusions').checked),
enablePopups: getPropertyValue('enablePopups', document.getElementById('enablePopups').checked),
showPointTitles: getPropertyValue('showPointTitles', document.getElementById('showPointTitles').checked),
visible: getPropertyValue('visible', document.getElementById('visible').checked)
};
}
function getPropertyValue(propertyName, value) {
if (removeDefaults && defaultOptions[propertyName] === value) {
return undefined;
}
return value;
}
function openTab(elm, tabName) {
var i, tabcontent, tablinks;
tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
tablinks = document.getElementsByClassName("tablinks");
for (i = 0; i < tablinks.length; i++) {
tablinks[i].className = tablinks[i].className.replace(" active", "");
}
document.getElementById(tabName).style.display = "block";
elm.className += " active";
}
</script>
<style>
#myMap {
position: relative;
width: calc(100% - 375px);
min-width: 290px;
height: 600px;
float: left;
}
.sidePanel {
width: 325px;
height: 580px;
float: left;
margin-right: 10px;
}
#CodeOutput {
width: 290px;
height: 300px;
overflow-y: auto;
}
.copyBtn {
float: right;
}
table td:nth-of-type(1) {
width: 130px;
}
.tab {
overflow: hidden;
border: 1px solid #ccc;
background-color: #f1f1f1;
}
.tab button {
background-color: inherit;
float: left;
border: none;
outline: none;
cursor: pointer;
padding: 6px 8px;
transition: 0.3s;
font-size: 14px;
}
.tab button:hover {
background-color: #ddd;
}
.tab button.active {
background-color: #ccc;
}
.tabcontent {
display: none;
padding: 6px 12px;
border: 1px solid #ccc;
border-top: none;
}
</style>
</head>
<body onload="getMap()">
<fieldset class="sidePanel">
<legend>Simple data layer options</legend>
This sample shows how the different options of the simple data layer affect rendering.
<br /><br />
Data set:<br />
<input type="button" value="Extruded KML polygons" onclick="loadDataSet('/data/Kml/internet_users_2005_choropleth_3D.kml')" />
<input type="button" value="Sample GeoRSS" onclick="loadDataSet('/data/GeoRSS/SampleGeoRSS.xml')" />
<br /><br />
<div class="tab">
<button class="tablinks active" onclick="openTab(this, 'SimpleDataLayerOptions')">Layer Options</button>
<button class="tablinks" onclick="openTab(this, 'Code')">Code</button>
</div>
<div id="SimpleDataLayerOptions" class="tabcontent" style="display:block;">
<table>
<tr title="Specifies if polygons that have a height property should be rendered as extruded polygons. Default: true">
<td>Allow extrusions:</td>
<td><input id="allowExtrusions" type="checkbox" onclick="updateLayer()" checked="checked" /></td>
</tr>
<tr title="Specifies if popups should appear when shapes are clicked. Default: true">
<td>Enable popups:</td>
<td><input id="enablePopups" type="checkbox" onclick="updateLayer()" checked="checked" /></td>
</tr>
<tr title="If a point feature has a title or name property, this option specifies if it should be displayed on the map under the marker. Default: false">
<td>Show point titles:</td>
<td><input id="showPointTitles" type="checkbox" onclick="updateLayer()" /></td>
</tr>
<tr title="Specifies if the layer is visible or not.">
<td>Visible:</td>
<td><input id="visible" type="checkbox" onclick="updateLayer()" checked="checked" /></td>
</tr>
</table>
<p>
In addition to the options in this tool, the simple data layer also has options for;
<ul>
<li>popupTemplate - used to customize the layout of content in the popups.</li>
</ul>
Note that the simple data layer uses style information stored in the properties of individual features to customize how each feature is rendered. The getLayer() function can be used to override this behaviour in the sub-layers.
</p>
</div>
<div id="Code" class="tabcontent">
<textarea id="CodeOutput"></textarea><br /><br />
<input id="RemoveDefaults" type="checkbox" onclick="updateLayer()" checked="checked" /> Remove defaults
<button class="copyBtn" data-clipboard-target="#CodeOutput">Copy to clipboard</button>
</div>
</fieldset>
<div id="myMap"></div>
</body>
</html>