Skip to content

Commit 7ef8e0a

Browse files
Merge pull request #1 from Chia-Chi-Shen/scaleControlSample
Scale control sample
2 parents c526221 + 635c28b commit 7ef8e0a

3 files changed

Lines changed: 167 additions & 87 deletions

File tree

‎Samples/Controls/Fullscreen control options/Fullscreen control options.html‎

Lines changed: 134 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
<link href="https://atlas.microsoft.com/sdk/javascript/mapcontrol/3/atlas.min.css" rel="stylesheet" />
1717
<script src="https://atlas.microsoft.com/sdk/javascript/mapcontrol/3/atlas.min.js"></script>
1818

19+
<!-- Add reference to the fullscreen control module. -->
20+
<script src="/lib/azure-maps/azure-maps-fullscreen-control.min.js"></script>
21+
1922
<script>
2023
var map, fullscreenControl;
2124

@@ -44,31 +47,42 @@
4447

4548
//Wait for map resources to be ready before loading controls.
4649
map.events.add('ready', function () {
50+
fullscreenControl = new atlas.control.FullscreenControl();
51+
52+
//Add events to the control.
53+
map.events.add('fullscreenchanged', fullscreenControl, displayEventInfo);
54+
4755
//Add control and a style control to the map.
48-
addFullscreenControl();
49-
map.controls.add(new atlas.control.StyleControl(), {
56+
map.controls.add([new atlas.control.StyleControl(), fullscreenControl], {
5057
position: 'top-right'
5158
});
5259
});
53-
5460
}
5561

56-
function addFullscreenControl() {
57-
map.controls.remove(fullscreenControl);
58-
59-
var style = getSelectValue('style');
60-
var hideIfUnsupported = document.getElementById('hideIfUnsupported').checked;
61-
var container = (getSelectValue('container') === 'map') ? null : '.testContainer';
62+
function displayEventInfo(isFullscreen) {
63+
document.getElementById('eventInfo').value = (isFullscreen) ? 'Not in fullscreen mode' : 'Is in fullscreen mode';
64+
}
6265

63-
fullscreenControl = new atlas.control.FullscreenControl({
64-
style: style,
65-
hideIfUnsupported: hideIfUnsupported,
66-
container: container
66+
function update() {
67+
fullscreenControl.setOptions({
68+
style: getSelectValue('style'),
69+
hideIfUnsupported: document.getElementById('hideIfUnsupported').checked,
70+
container: (getSelectValue('container') === 'map') ? null : '.testContainer'
6771
});
72+
}
6873

69-
map.controls.add(fullscreenControl, {
70-
position: 'top-right'
71-
});
74+
function openTab(elm, tabName) {
75+
var i, tabcontent, tablinks;
76+
tabcontent = document.getElementsByClassName("tabcontent");
77+
for (i = 0; i < tabcontent.length; i++) {
78+
tabcontent[i].style.display = "none";
79+
}
80+
tablinks = document.getElementsByClassName("tablinks");
81+
for (i = 0; i < tablinks.length; i++) {
82+
tablinks[i].className = tablinks[i].className.replace(" active", "");
83+
}
84+
document.getElementById(tabName).style.display = "block";
85+
elm.className += " active";
7286
}
7387

7488
function getSelectValue(id) {
@@ -77,80 +91,113 @@
7791
}
7892
</script>
7993
<style>
80-
.testContainer {
81-
background-color: white;
82-
}
83-
84-
.sidePanel {
85-
width: 325px;
86-
height: 580px;
87-
float: left;
88-
margin-right: 10px;
89-
}
90-
91-
#myMap {
92-
position: relative;
93-
width: calc(100% - 375px);
94-
min-width: 290px;
95-
height: 600px;
96-
float: left;
97-
}
94+
.testContainer {
95+
background-color: white;
96+
}
97+
98+
.sidePanel {
99+
width: 325px;
100+
height: 580px;
101+
float: left;
102+
margin-right: 10px;
103+
}
104+
105+
#myMap {
106+
position: relative;
107+
width: calc(100% - 375px);
108+
min-width: 290px;
109+
height: 600px;
110+
float: left;
111+
}
112+
113+
#eventInfo {
114+
width: 300px;
115+
height: 420px;
116+
overflow-y: auto;
117+
}
118+
119+
.tab {
120+
overflow: hidden;
121+
border: 1px solid #ccc;
122+
background-color: #f1f1f1;
123+
}
124+
125+
.tab button {
126+
background-color: inherit;
127+
float: left;
128+
border: none;
129+
outline: none;
130+
cursor: pointer;
131+
padding: 6px 8px;
132+
transition: 0.3s;
133+
font-size: 14px;
134+
}
135+
136+
.tab button:hover {
137+
background-color: #ddd;
138+
}
139+
140+
.tab button.active {
141+
background-color: #ccc;
142+
}
143+
144+
.tabcontent {
145+
display: none;
146+
padding: 6px 12px;
147+
border: 1px solid #ccc;
148+
border-top: none;
149+
}
98150
</style>
99-
</head>
100-
<body onload="getMap()">
151+
</head>
152+
<body onload="getMap()">
153+
101154
<div class="testContainer">
102-
<div class="sidePanel">
103-
<fieldset style="width: 320px; margin-bottom: 10px">
104-
<legend>Fullscreen control options</legend>
105-
This sample shows how to create a fullscreen control and all of its
106-
options.
155+
<fieldset class="sidePanel">
156+
<legend>Fullscreen control options</legend>
157+
This sample shows all the options of the fullscreen control.
158+
This samples uses the open source <a href="https://github.com/Azure-Samples/azure-maps-fullscreen-control" target="_blank">Azure Maps Fullscreen Control module</a>.
159+
<br /><br />
160+
161+
<div class="tab">
162+
<button class="tablinks active" onclick="openTab(this, 'Options')">Options</button>
163+
<button class="tablinks" onclick="openTab(this, 'EventInfo')">Event info</button>
164+
</div>
165+
166+
<div id="Options" class="tabcontent" style="display:block;">
167+
<table>
168+
<tr title="The HTML element that should be made fullscreen.">
169+
<td>Container:</td>
170+
<td>
171+
<select id="container" onchange="update()" title="Container">
172+
<option>HTML element</option>
173+
<option selected="selected">map</option>
174+
</select>
175+
</td>
176+
</tr>
177+
<tr title="Specifies if the control should be hidden if fullscreen is not supported by the browser. ">
178+
<td>Hide if unsupported:</td>
179+
<td><input id="hideIfUnsupported" title="Hide if unsupported" type="checkbox" checked="checked" onclick="update()" /></td>
180+
</tr>
181+
<tr title="The style of the control.">
182+
<td>Style:</td>
183+
<td>
184+
<select id="style" onchange="update()" title="Style">
185+
<option>auto</option>
186+
<option>dark</option>
187+
<option selected="selected">light</option>
188+
</select>
189+
</td>
190+
</tr>
191+
</table>
192+
</div>
193+
194+
<div id="EventInfo" class="tabcontent">
195+
<b>Event info</b><br/>
196+
<textarea id="eventInfo" title="Event info"></textarea>
197+
</div>
107198
</fieldset>
108-
<table>
109-
<tr title="The HTML element that should be made fullscreen.">
110-
<td>Container:</td>
111-
<td>
112-
<select
113-
id="container"
114-
onchange="addFullscreenControl()"
115-
title="Container"
116-
>
117-
<option>HTML element</option>
118-
<option selected="selected">map</option>
119-
</select>
120-
</td>
121-
</tr>
122-
<tr
123-
title="Specifies if the control should be hidden if fullscreen is not supported by the browser. "
124-
>
125-
<td>Hide if unsupported:</td>
126-
<td>
127-
<input
128-
id="hideIfUnsupported"
129-
title="Hide if unsupported"
130-
type="checkbox"
131-
checked="checked"
132-
onclick="addFullscreenControl()"
133-
/>
134-
</td>
135-
</tr>
136-
<tr title="The style of the control.">
137-
<td>Style:</td>
138-
<td>
139-
<select
140-
id="style"
141-
onchange="addFullscreenControl()"
142-
title="Style"
143-
>
144-
<option>auto</option>
145-
<option>dark</option>
146-
<option selected="selected">light</option>
147-
</select>
148-
</td>
149-
</tr>
150-
</table>
151-
</div>
152-
153-
<div id="myMap"></div>
199+
200+
<div id="myMap"></div>
154201
</div>
155202
</body>
156203
</html>

‎Samples/Controls/Fullscreen control/Fullscreen control.html‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
<link href="https://atlas.microsoft.com/sdk/javascript/mapcontrol/3/atlas.min.css" rel="stylesheet" />
1717
<script src="https://atlas.microsoft.com/sdk/javascript/mapcontrol/3/atlas.min.js"></script>
1818

19+
<!-- Load in the JavaScript that has our custom control. -->
20+
<script src="/lib/azure-maps/azure-maps-fullscreen-control.min.js"></script>
21+
1922
<script>
2023
var map;
2124

@@ -66,6 +69,7 @@
6669
<fieldset style="width:calc(100% - 30px);min-width:290px;margin-top:10px;">
6770
<legend>Fullscreen control</legend>
6871
This sample shows how to add a fullscreen button to the map to display it in fullscreen mode.
72+
This samples uses the open source <a href="https://github.com/Azure-Samples/azure-maps-fullscreen-control" target="_blank" title="Azure Maps Fullscreen Control module">Azure Maps Fullscreen Control module</a>.
6973
</fieldset>
7074
</body>
7175
</html>

‎Samples/Controls/Map Navigation Control Options/Map Navigation Control Options.html‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,13 @@
9292
layout: pickerLayout
9393
}));
9494

95+
//Create a scale control and add it to the map.
96+
controls.push(new atlas.control.ScaleControl({
97+
maxWidth: parseFloat(getSelectValue('scaleMaxWidth')),
98+
unit: getSelectValue('scaleUnit'),
99+
style: controlStyle
100+
}));
101+
95102
//Add controls to the map.
96103
map.controls.add(controls, {
97104
position: positionOption
@@ -224,6 +231,28 @@
224231
</select>
225232
</td>
226233
</tr>
234+
235+
<tr title="The maximum length of the scale control in pixels.">
236+
<td>Scale Max Width:</td>
237+
<td>
238+
<select id="scaleMaxWidth" onchange="addControls()" title="Scale Max Width">
239+
<option>50</option>
240+
<option selected="selected">100</option>
241+
<option>200</option>
242+
<option>400</option>
243+
</select>
244+
</td>
245+
</tr>
246+
<tr title="The unit of the distance shown on scale control.">
247+
<td>Scale Unit:</td>
248+
<td>
249+
<select id="scaleUnit" onchange="addControls()" title="Scale Unit">
250+
<option>imperial</option>
251+
<option selected="selected">metric</option>
252+
<option>nautical</option>
253+
</select>
254+
</td>
255+
</tr>
227256
</table>
228257
</div>
229258

0 commit comments

Comments
 (0)