-
Notifications
You must be signed in to change notification settings - Fork 449
/
Swipe between two maps.html
176 lines (153 loc) · 6.91 KB
/
Swipe between two maps.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
<!DOCTYPE html>
<html lang="en">
<head>
<title>Swipe between two maps - 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 to swipe between two overlapping synchronized maps to view different data sets." />
<meta name="keywords" content="Microsoft maps, map, gis, API, SDK, synchronized maps, swipe map" />
<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>
<!-- Load in the JavaScript for the swipe map module. -->
<script src="/lib/azure-maps/azure-maps-swipe-map.min.js"></script>
<script>
var primaryMap, secondaryMap, primaryDataSource, secondaryDataSource;
function getMap() {
//Add authentication details for connecting to Azure Maps.
var 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(function (response) {
return response.text();
}).then(function (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]'
};
//Initialize a map instance.
primaryMap = new atlas.Map('primaryMap', {
center: [-100, 35],
zoom: 3,
style: 'grayscale_dark',
view: 'Auto',
authOptions: authOptions
});
secondaryMap = new atlas.Map('secondaryMap', {
style: 'grayscale_dark',
view: 'Auto',
authOptions: authOptions
});
new atlas.SwipeMap(primaryMap, secondaryMap);
//Add some data to the left map.
primaryMap.events.add('ready', function () {
primaryDataSource = new atlas.source.DataSource();
primaryMap.sources.add(primaryDataSource);
primaryDataSource.importDataFromUrl('/data/geojson/US_County_Unemployment_2017.geojson');
//Choropleth based on unemployment rates in the US counties.
primaryMap.layers.add(new atlas.layer.PolygonLayer(primaryDataSource, null, {
fillColor: [
'step',
['get', 'unemployment_rate'],
'#FFEDA0',
3, '#FED976',
4, '#FD8D3C',
5, '#E31A1C',
6, '#800026'
],
fillOpacity: 0.8
}), 'labels');
});
//Add some data to the right map.
secondaryMap.events.add('ready', function () {
secondaryDataSource = new atlas.source.DataSource();
secondaryMap.sources.add(secondaryDataSource);
secondaryDataSource.importDataFromUrl('/data/geojson/US_County_Unemployment_2017.geojson');
//Choropleth based on suze of labor force in the US counties.
secondaryMap.layers.add(new atlas.layer.PolygonLayer(secondaryDataSource, null, {
fillColor: [
'step',
['get', 'labor_force'],
'#fff7f3',
10000, '#fcc5c0',
50000, '#dd3497',
100000, '#48006a'
],
fillOpacity: 0.8
}), 'labels');
});
}
</script>
<style>
.mapContainer {
position: relative;
width: 100%;
height: 600px;
}
.map {
position: absolute;
top: 0;
left: 0;
width: 100%;
min-width: 290px;
height: 600px;
}
.legend {
font-family: Arial;
font-size: 12px;
position: absolute;
top: 15px;
background-color: #fff;
padding: 5px;
border-radius: 5px;
}
.legend i {
width: 12px;
height: 12px;
float: left;
margin-right: 8px;
opacity: 0.7;
}
</style>
</head>
<body onload="getMap()">
<div class="mapContainer">
<div id="primaryMap" class="map"></div>
<div id="secondaryMap" class="map"></div>
</div>
<div class="legend" style="left: 15px;">
<b>Unemployment rate</b>
<table>
<tr><td><i style="background:#800026" /></td><td>6%+</td></tr>
<tr><td><i style="background:#E31A1C" /></td><td>5% - 5.99%</td></tr>
<tr><td><i style="background:#FD8D3C" /></td><td>4% - 4.99%</td></tr>
<tr><td><i style="background:#FED976" /></td><td>3% - 3.99%</td></tr>
<tr><td><i style="background:#FFEDA0" /></td><td>0% - 2.99%</td></tr>
</table>
</div>
<div class="legend" style="right: 15px;">
<b>Size of labor force</b>
<table>
<tr><td><i style="background:#48006a" /></td><td>100,000+</td></tr>
<tr><td><i style="background:#dd3497" /></td><td>50,000 - 99,999</td></tr>
<tr><td><i style="background:#fcc5c0" /></td><td>10,000 - 49,999</td></tr>
<tr><td><i style="background:#fff7f3" /></td><td>0 - 9,999</td></tr>
</table>
</div>
<fieldset style="width:calc(100% - 30px);min-width:290px;margin-top:10px;">
<legend>Swipe between two maps</legend>
This sample shows how to swipe between two overlapping synchronized maps to view different data sets.
This sample uses the open source Azure Maps <a href="https://github.com/Azure-Samples/azure-maps-swipe-map" target="_blank">Swipe Map</a> module.
</fieldset>
</body>
</html>