|
10 | 10 | <meta name="description" content="This sample shows how to use the drawing tools to search for points of interests within drawn areas." /> |
11 | 11 | <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" /> |
12 | 12 | <meta name="author" content="Microsoft Azure Maps" /> |
13 | | - <meta name="version" content="1.0" /> |
| 13 | + <meta name="version" content="2.0" /> |
14 | 14 | <meta name="screenshot" content="screenshot.jpg" /> |
15 | 15 |
|
16 | 16 | <!-- Add references to the Azure Maps Map control JavaScript and CSS files. --> |
|
21 | 21 | <link rel="stylesheet" href="https://atlas.microsoft.com/sdk/javascript/drawing/1/atlas-drawing.min.css" type="text/css" /> |
22 | 22 | <script src="https://atlas.microsoft.com/sdk/javascript/drawing/1/atlas-drawing.min.js"></script> |
23 | 23 |
|
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> |
26 | 26 |
|
27 | 27 | <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 | + } |
29 | 51 |
|
30 | 52 | function getMap() { |
31 | 53 | //Initialize a map instance. |
|
34 | 56 | zoom: 12, |
35 | 57 | view: 'Auto', |
36 | 58 |
|
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 | + } |
53 | 72 | }); |
54 | 73 |
|
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 | | - |
61 | 74 | //Wait until the map resources are ready. |
62 | 75 | map.events.add('ready', function () { |
63 | 76 |
|
|
0 commit comments