Skip to content

Commit 29f5d38

Browse files
authored
Merge pull request #164 from zhz0704/custom-basemap-samples
Update style options sample to include styleOverrides
2 parents 3a46301 + 5dd5152 commit 29f5d38

1 file changed

Lines changed: 59 additions & 1 deletion

File tree

‎Samples/Map/Map style options/Map style options.html‎

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,18 @@
4343
//subscriptionKey: '[YOUR_AZURE_MAPS_KEY]'
4444
}
4545
});
46+
47+
//Add events to update the map-info panel.
48+
map.events.add("dragend", () => updateState());
49+
map.events.add("zoomend", () => updateState());
4650

4751
//Wait until the map resources are ready.
4852
map.events.add('ready', function () {
4953
defaultOptions = map.getStyle();
5054

5155
//Update the map with the options in the input fields.
5256
updateStyles();
57+
updateState();
5358
});
5459

5560
new ClipboardJS('.copyBtn');
@@ -100,9 +105,17 @@
100105
renderWorldCopies: getPropertyValue('renderWorldCopies', document.getElementById('renderWorldCopies').checked),
101106
showFeedbackLink: getPropertyValue('showFeedbackLink', document.getElementById('showFeedbackLink').checked),
102107
showLogo: getPropertyValue('showLogo', document.getElementById('showLogo').checked),
108+
showLabels: getPropertyValue('showLabels', document.getElementById('showLabels').checked),
103109
showTileBoundaries: getPropertyValue('showTileBoundaries', document.getElementById('showTileBoundaries').checked),
104110
style: getPropertyValue('style', getSelectValue('style')),
105-
light: (Object.keys(light).length > 0)? light: undefined
111+
light: (Object.keys(light).length > 0)? light: undefined,
112+
styleOverrides: (obj => Object.keys(obj).length > 0 ? obj : undefined)(Object.fromEntries([
113+
['countryRegion', { borderVisible: document.getElementById('showCountryBorders').checked }],
114+
['adminDistrict', { borderVisible: document.getElementById('showAdminDistrictBorders').checked }],
115+
['adminDistrict2', { borderVisible: document.getElementById('showSecondAdminDistrictBorders').checked }],
116+
['buildingFootprint', { visible: document.getElementById('showBuildingFootprints').checked }],
117+
['roadDetails', { visible: document.getElementById('showRoadDetails').checked }]
118+
].filter(([_, v]) => !removeDefaults || !v.visible))),
106119
};
107120
}
108121

@@ -144,6 +157,14 @@
144157
document.getElementById(tabName).style.display = "block";
145158
elm.className += " active";
146159
}
160+
161+
function updateState() {
162+
var camera = map.getCamera();
163+
document.getElementById("map-info").innerText =
164+
`Zoom: ${camera.zoom.toFixed(1)} / ` +
165+
`Lat: ${camera.center[1].toFixed(5)} / ` +
166+
`Lng: ${camera.center[0].toFixed(5)}`;
167+
}
147168
</script>
148169
<style>
149170
#myMap {
@@ -154,6 +175,15 @@
154175
float: left;
155176
}
156177

178+
#panel {
179+
position: absolute;
180+
top: 14px;
181+
left: 378px;
182+
padding: 10px;
183+
border-radius: 5px;
184+
background-color: white;
185+
}
186+
157187
.sidePanel {
158188
width: 325px;
159189
height: 580px;
@@ -165,6 +195,7 @@
165195
width: 290px;
166196
height: 390px;
167197
overflow-y: auto;
198+
tab-size: 4;
168199
}
169200

170201
.copyBtn {
@@ -236,6 +267,30 @@
236267
<td>Show logo:</td>
237268
<td><input id="showLogo" type="checkbox" onclick="updateStyles()" checked="checked" /></td>
238269
</tr>
270+
<tr title="Specifies if the map should display labels.">
271+
<td>Show labels:</td>
272+
<td><input id="showLabels" type="checkbox" onclick="updateStyles()" checked="checked" /></td>
273+
</tr>
274+
<tr title="Specifies if the map should display country borders.">
275+
<td>Show country borders:</td>
276+
<td><input id="showCountryBorders" type="checkbox" onclick="updateStyles()" checked="checked" /></td>
277+
</tr>
278+
<tr title="Specifies if the map should display admin district borders.">
279+
<td>Show admin district borders:</td>
280+
<td><input id="showAdminDistrictBorders" type="checkbox" onclick="updateStyles()" checked="checked" /></td>
281+
</tr>
282+
<tr title="Specifies if the map should display second admin district borders.">
283+
<td>Show second admin district borders:</td>
284+
<td><input id="showSecondAdminDistrictBorders" type="checkbox" onclick="updateStyles()" checked="checked" /></td>
285+
</tr>
286+
<tr title="Specifies if the map should display building footprints.">
287+
<td>Show building footprints:</td>
288+
<td><input id="showBuildingFootprints" type="checkbox" onclick="updateStyles()" checked="checked" /></td>
289+
</tr>
290+
<tr title="Specifies if the map should display road details.">
291+
<td>Show road details:</td>
292+
<td><input id="showRoadDetails" type="checkbox" onclick="updateStyles()" checked="checked" /></td>
293+
</tr>
239294
<tr title="Specifies if the map should render an outline around each tile and the tile ID. These tile boundaries are useful for debugging. The uncompressed file size of the first vector source is drawn in the top left corner of each tile, next to the tile ID. ">
240295
<td>Show tile boundaries:</td>
241296
<td><input id="showTileBoundaries" type="checkbox" onclick="updateStyles()" /></td>
@@ -339,5 +394,8 @@
339394
</fieldset>
340395

341396
<div id="myMap"></div>
397+
<div id="panel">
398+
<div id="map-info"></div>
399+
</div>
342400
</body>
343401
</html>

0 commit comments

Comments
 (0)