Skip to content

Commit f377f85

Browse files
committed
Services Module
1 parent 2624a4b commit f377f85

2 files changed

Lines changed: 39 additions & 26 deletions

File tree

‎Samples/Drawing Tools Module/Draw and search polygon area/Draw and search polygon area.html‎

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<meta name="description" content="This sample shows how to use the drawing tools to search for points of interests within drawn areas." />
1111
<meta name="keywords" content="Microsoft maps, map, gis, API, SDK, drawing tools, circle, rectangle, polygon, paint, events, services, module, search, points of interest, POI, within, intersects, intersection" />
1212
<meta name="author" content="Microsoft Azure Maps" />
13-
<meta name="version" content="1.0" />
13+
<meta name="version" content="2.0" />
1414
<meta name="screenshot" content="screenshot.jpg" />
1515

1616
<!-- Add references to the Azure Maps Map control JavaScript and CSS files. -->
@@ -21,11 +21,33 @@
2121
<link rel="stylesheet" href="https://atlas.microsoft.com/sdk/javascript/drawing/1/atlas-drawing.min.css" type="text/css" />
2222
<script src="https://atlas.microsoft.com/sdk/javascript/drawing/1/atlas-drawing.min.js"></script>
2323

24-
<!-- Add a reference to the Azure Maps Services Module JavaScript file. -->
25-
<script src="https://atlas.microsoft.com/sdk/javascript/service/2/atlas-service.min.js"></script>
24+
<!-- Add a reference to the Azure Maps Rest Helper JavaScript file. -->
25+
<script src="https://samples.azuremaps.com/lib/azure-maps/azure-maps-helper.min.js"></script>
2626

2727
<script>
28-
var map, searchURL, datasource, drawingManager, popup;
28+
var map, datasource, drawingManager, popup;
29+
30+
// Your Azure Maps client id for accessing your Azure Maps account.
31+
var azureMapsClientId = 'e6b6ab59-eb5d-4d25-aa57-581135b927f0';
32+
33+
// URL to your authentication service that retrieves an Microsoft Entra ID Token.
34+
var tokenServiceUrl = 'https://samples.azuremaps.com/api/GetAzureMapsToken';
35+
36+
// URL for the Azure Maps Search POI API.
37+
var searchPOIUrl = 'https://{azMapsDomain}/search/poi/json?api-version=1.0&query={query}&limit={limit}&lat={lat}&lon={lon}&radius={radius}&view=Auto';
38+
39+
// URL for the Azure Maps Search Inside Geometry API.
40+
var searchGeometryUrl = 'https://{azMapsDomain}/search/geometry/json?api-version=1.0&query={query}&limit={limit}&view=Auto';
41+
42+
// Function to retrieve an Azure Maps access token.
43+
function getToken(resolve, reject, map) {
44+
fetch(tokenServiceUrl).then(response => {
45+
if (response.ok) {
46+
return response.text();
47+
}
48+
throw new Error('Failed to retrieve Azure Maps token.');
49+
}).then(token => resolve(token)).catch(error => reject(error));
50+
}
2951

3052
function getMap() {
3153
//Initialize a map instance.
@@ -34,30 +56,21 @@
3456
zoom: 12,
3557
view: 'Auto',
3658

37-
//Add authentication details for connecting to Azure Maps.
38-
authOptions: {
39-
//Use Microsoft Entra ID authentication.
40-
authType: 'anonymous',
41-
clientId: 'e6b6ab59-eb5d-4d25-aa57-581135b927f0', //Your Azure Maps client id for accessing your Azure Maps account.
42-
getToken: function (resolve, reject, map) {
43-
//URL to your authentication service that retrieves an Microsoft Entra ID Token.
44-
var tokenServiceUrl = 'https://samples.azuremaps.com/api/GetAzureMapsToken';
45-
46-
fetch(tokenServiceUrl).then(r => r.text()).then(token => resolve(token));
47-
}
48-
49-
//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.
50-
//authType: 'subscriptionKey',
51-
//subscriptionKey: '[YOUR_AZURE_MAPS_KEY]'
52-
}
59+
// Add authentication details for connecting to Azure Maps.
60+
authOptions: {
61+
// Use Microsoft Entra ID authentication.
62+
authType: 'anonymous',
63+
clientId: azureMapsClientId,
64+
getToken: getToken
65+
66+
// Alternatively, use an Azure Maps key.
67+
// Get an Azure Maps key at https://azure.com/maps.
68+
// NOTE: The primary key should be used as the key.
69+
//authType: 'subscriptionKey',
70+
//subscriptionKey: '[YOUR_AZURE_MAPS_KEY]'
71+
}
5372
});
5473

55-
//Use MapControlCredential to share authentication between a map control and the service module.
56-
var pipeline = atlas.service.MapsURL.newPipeline(new atlas.service.MapControlCredential(map));
57-
58-
//Create an instance of the SearchURL client.
59-
searchURL = new atlas.service.SearchURL(pipeline);
60-
6174
//Wait until the map resources are ready.
6275
map.events.add('ready', function () {
6376

2.07 KB
Loading

0 commit comments

Comments
 (0)