@azure-rest/maps-render 1.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +224 -0
- package/dist/index.js +365 -0
- package/dist/index.js.map +1 -0
- package/dist-esm/src/createMultiCollection.js +13 -0
- package/dist-esm/src/createMultiCollection.js.map +1 -0
- package/dist-esm/src/createPathQuery.js +97 -0
- package/dist-esm/src/createPathQuery.js.map +1 -0
- package/dist-esm/src/createPinsQuery.js +74 -0
- package/dist-esm/src/createPinsQuery.js.map +1 -0
- package/dist-esm/src/generated/clientDefinitions.js +4 -0
- package/dist-esm/src/generated/clientDefinitions.js.map +1 -0
- package/dist-esm/src/generated/index.js +11 -0
- package/dist-esm/src/generated/index.js.map +1 -0
- package/dist-esm/src/generated/isUnexpected.js +77 -0
- package/dist-esm/src/generated/isUnexpected.js.map +1 -0
- package/dist-esm/src/generated/mapsRenderClient.js +25 -0
- package/dist-esm/src/generated/mapsRenderClient.js.map +1 -0
- package/dist-esm/src/generated/outputModels.js +4 -0
- package/dist-esm/src/generated/outputModels.js.map +1 -0
- package/dist-esm/src/generated/parameters.js +4 -0
- package/dist-esm/src/generated/parameters.js.map +1 -0
- package/dist-esm/src/generated/responses.js +4 -0
- package/dist-esm/src/generated/responses.js.map +1 -0
- package/dist-esm/src/index.js +9 -0
- package/dist-esm/src/index.js.map +1 -0
- package/dist-esm/src/mapsRender.js +29 -0
- package/dist-esm/src/mapsRender.js.map +1 -0
- package/dist-esm/src/positionToTileXY.js +44 -0
- package/dist-esm/src/positionToTileXY.js.map +1 -0
- package/package.json +130 -0
- package/review/maps-render.api.md +555 -0
- package/types/maps-render-rest.d.ts +1225 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Microsoft
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
# Azure MapsRender REST client library for JavaScript
|
|
2
|
+
|
|
3
|
+
Azure Maps Render Client
|
|
4
|
+
|
|
5
|
+
\*\*If you are not familiar with our REST client, please spend 5 minutes to take a look at our [REST client docs](https://github.com/Azure/azure-sdk-for-js/blob/main/documentation/rest-clients.md) to use this library, the REST client provides a light-weighted & developer friendly way to call azure rest api
|
|
6
|
+
|
|
7
|
+
Key links:
|
|
8
|
+
|
|
9
|
+
- [Source code][source_code]
|
|
10
|
+
- [Package (NPM)][npm_package]
|
|
11
|
+
- [API reference documentation][api_ref]
|
|
12
|
+
- [Product Information][product_info]
|
|
13
|
+
|
|
14
|
+
## Getting started
|
|
15
|
+
|
|
16
|
+
### Currently supported environments
|
|
17
|
+
|
|
18
|
+
- [LTS versions of Node.js][nodejs_release]
|
|
19
|
+
- Latest versions of Safari, Chrome, Edge and Firefox.
|
|
20
|
+
|
|
21
|
+
### Prerequisites
|
|
22
|
+
|
|
23
|
+
- You must have an [Azure subscription][az_subscription] to use this package.
|
|
24
|
+
- An [Azure Maps account][az_maps_account_management]. You can create the resource via the [Azure Portal][azure_portal], the [Azure PowerShell][azure_powershell], or the [Azure CLI][azure_cli].
|
|
25
|
+
|
|
26
|
+
If you use Azure CLI, replace `<resource-group-name>` and `<map-account-name>` of your choice, and select a proper [pricing tier][az_map_pricing] based on your needs via the `<sku-name>` parameter. Please refer to [Azure Maps Reference for Azure CLI][az_map_az_cli] for more details.
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
az maps account create --resource-group <resource-group-name> --name <map-account-name> --sku <sku-name>
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Install the `@azure-rest/maps-render` package
|
|
33
|
+
|
|
34
|
+
Install the Azure Maps Render REST client library for JavaScript with `npm`:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
npm install @azure-rest/maps-render
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Create and authenticate a `MapsRenderClient`
|
|
41
|
+
|
|
42
|
+
You'll need a `credential` instance for authentication when creating the `MapsRenderClient` instance used to access the Azure Maps render APIs. You can use either an Azure Active Directory (Azure AD) credential or an Azure subscription key to authenticate. For more information on authentication, see [Authentication with Azure Maps][az_map_auth].
|
|
43
|
+
|
|
44
|
+
#### Using an Azure AD credential
|
|
45
|
+
|
|
46
|
+
To use an [Azure Active Directory (AAD) token credential](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/identity/identity/samples/AzureIdentityExamples.md#authenticating-with-a-pre-fetched-access-token),
|
|
47
|
+
provide an instance of the desired credential type obtained from the
|
|
48
|
+
[@azure/identity](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#credentials) library.
|
|
49
|
+
|
|
50
|
+
To authenticate with AAD, you must first `npm` install [`@azure/identity`](https://www.npmjs.com/package/@azure/identity)
|
|
51
|
+
|
|
52
|
+
After setup, you can choose which type of [credential](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#credentials) from `@azure/identity` to use.
|
|
53
|
+
As an example, [DefaultAzureCredential](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#defaultazurecredential)
|
|
54
|
+
can be used to authenticate the client.
|
|
55
|
+
|
|
56
|
+
You'll need to register the new Azure AD application and grant access to Azure Maps by assigning the required role to your service principal. For more information, see [Host a daemon on non-Azure resources](https://learn.microsoft.com/azure/azure-maps/how-to-secure-daemon-app#host-a-daemon-on-non-azure-resources). Set the values of the client ID, tenant ID, and client secret of the AAD application as environment variables:
|
|
57
|
+
`AZURE_CLIENT_ID`, `AZURE_TENANT_ID`, `AZURE_CLIENT_SECRET`.
|
|
58
|
+
|
|
59
|
+
You will also need to specify the Azure Maps resource you intend to use by specifying the `clientId` in the client options.
|
|
60
|
+
The Azure Maps resource client id can be found in the Authentication sections in the Azure Maps resource. Please refer to the [documentation](https://docs.microsoft.com/azure/azure-maps/how-to-manage-authentication#view-authentication-details) on how to find it.
|
|
61
|
+
|
|
62
|
+
```javascript
|
|
63
|
+
const MapsRender = require("@azure-rest/maps-render").default;
|
|
64
|
+
const { DefaultAzureCredential } = require("@azure/identity");
|
|
65
|
+
|
|
66
|
+
const credential = new DefaultAzureCredential();
|
|
67
|
+
const client = MapsRender(credential, "<maps-account-client-id>");
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
#### Using a Subscription Key Credential
|
|
71
|
+
|
|
72
|
+
You can authenticate with your Azure Maps Subscription Key. Please install the `@azure/core-auth` package:
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
npm install @azure/core-auth
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
```javascript
|
|
79
|
+
const MapsRender = require("@azure-rest/maps-render").default;
|
|
80
|
+
const AzureKeyCredential = require("@azure/core-auth");
|
|
81
|
+
|
|
82
|
+
const credential = new AzureKeyCredential("<subscription-key>");
|
|
83
|
+
const client = MapsRender(credential);
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Key concepts
|
|
87
|
+
|
|
88
|
+
### MapsRenderClient
|
|
89
|
+
|
|
90
|
+
`MapsRenderClient` is the primary interface for developers using the Azure Maps Render client library. Explore the methods on this client object to understand the different features of the Azure Maps Render service that you can access.
|
|
91
|
+
|
|
92
|
+
## Examples
|
|
93
|
+
|
|
94
|
+
The following sections provide several code snippets covering some of the most common Azure Maps Render tasks, including:
|
|
95
|
+
|
|
96
|
+
- [Request map tiles in vector or raster formats](#request-map-tiles-in-vector-or-raster-formats)
|
|
97
|
+
- [Request map copyright attribution information](#request-map-copyright-attribution-information)
|
|
98
|
+
- [Request metadata for a tileset](#request-metadata-for-a-tileset)
|
|
99
|
+
|
|
100
|
+
### Request map tiles in vector or raster formats
|
|
101
|
+
|
|
102
|
+
You can request map tiles in vector or raster formats. These tiles are typically to be integrated into a map control or SDK.
|
|
103
|
+
Some example tiles that can be requested are Azure Maps road tiles, real-time Weather Radar tiles or the map tiles created using [Azure Maps Creator](https://docs.microsoft.com/shows/internet-of-things-show/introducing-azure-maps-creator).
|
|
104
|
+
|
|
105
|
+
```javascript
|
|
106
|
+
const { createWriteStream } = require("fs");
|
|
107
|
+
const { positionToTileXY } = require("@azure-rest/maps-render");
|
|
108
|
+
|
|
109
|
+
const zoom = 6;
|
|
110
|
+
// Use the helper function `positionToTileXY` to get the tile index from the coordinate.
|
|
111
|
+
const { x, y } = positionToTileXY([47.61559, -122.33817], 6, "256");
|
|
112
|
+
const response = await client
|
|
113
|
+
.path("/map/tile")
|
|
114
|
+
.get({
|
|
115
|
+
queryParameters: {
|
|
116
|
+
tilesetId: "microsoft.base.road",
|
|
117
|
+
zoom,
|
|
118
|
+
x,
|
|
119
|
+
y,
|
|
120
|
+
},
|
|
121
|
+
})
|
|
122
|
+
.asNodeStream();
|
|
123
|
+
|
|
124
|
+
// Handle the error.
|
|
125
|
+
if (!response.body) {
|
|
126
|
+
throw Error("No response body");
|
|
127
|
+
}
|
|
128
|
+
response.body.pipe(createWriteStream("tile.png"));
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Request map copyright attribution information
|
|
132
|
+
|
|
133
|
+
You can request map copyright attribution information for a section of a tileset.
|
|
134
|
+
A tileset is a collection of raster or vector data broken up into a uniform grid of square tiles at preset zoom levels. Every tileset has a tilesetId to use when making requests. The supported tilesetIds are listed [here](https://docs.microsoft.com/rest/api/maps/render-v2/get-map-attribution?tabs=HTTP#tilesetid).
|
|
135
|
+
|
|
136
|
+
```javascript
|
|
137
|
+
const { isUnexpected } = require("@azure-rest/maps-render");
|
|
138
|
+
|
|
139
|
+
const response = await client.path("/map/attribution").get({
|
|
140
|
+
queryParameters: {
|
|
141
|
+
tilesetId: "microsoft.base",
|
|
142
|
+
zoom: 6,
|
|
143
|
+
/** The order is [SouthwestCorner_Longitude, SouthwestCorner_Latitude, NortheastCorner_Longitude, NortheastCorner_Latitude] */
|
|
144
|
+
bounds: [-122.414162, 47.57949, -122.247157, 47.668372],
|
|
145
|
+
},
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
// Handle exception.
|
|
149
|
+
if (isUnexpected(response)) {
|
|
150
|
+
throw response.body.error;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
console.log("Copyright attribution for microsoft.base: ");
|
|
154
|
+
baseResponse.body.copyrights.forEach((copyright) => console.log(copyright));
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
### Request metadata for a tileset
|
|
158
|
+
|
|
159
|
+
You can request metadata for a tileset in TileJSON format using the following code snippet.
|
|
160
|
+
|
|
161
|
+
```javascript
|
|
162
|
+
const { isUnexpected } = require("@azure-rest/maps-render");
|
|
163
|
+
|
|
164
|
+
const response = await client.path("/map/tileset").get({
|
|
165
|
+
queryParameters: {
|
|
166
|
+
tilesetId: "microsoft.base",
|
|
167
|
+
},
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
if (isUnexpected(response)) {
|
|
171
|
+
throw response.body.error;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
console.log("The metadata of Microsoft Base tileset: ");
|
|
175
|
+
const { maxzoom, minzoom, bounds = [] } = response.body;
|
|
176
|
+
console.log(`The zoom range started from ${minzoom} to ${maxzoom}`);
|
|
177
|
+
console.log(
|
|
178
|
+
`The left bound is ${bounds[0]}, bottom bound is ${bounds[1]}, right bound is ${bounds[2]}, and top bound is ${bounds[3]}`
|
|
179
|
+
);
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
## Troubleshooting
|
|
183
|
+
|
|
184
|
+
### Logging
|
|
185
|
+
|
|
186
|
+
Enabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:
|
|
187
|
+
|
|
188
|
+
```javascript
|
|
189
|
+
const { setLogLevel } = require("@azure/logger");
|
|
190
|
+
|
|
191
|
+
setLogLevel("info");
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
For more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/core/logger).
|
|
195
|
+
|
|
196
|
+
## Next steps
|
|
197
|
+
|
|
198
|
+
Please take a look at the [samples][samples] directory for detailed examples on how to use this library.
|
|
199
|
+
|
|
200
|
+
## Contributing
|
|
201
|
+
|
|
202
|
+
If you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/master/CONTRIBUTING.md) to learn more about how to build and test the code.
|
|
203
|
+
|
|
204
|
+
## Related projects
|
|
205
|
+
|
|
206
|
+
- [Microsoft Azure SDK for JavaScript](https://github.com/Azure/azure-sdk-for-js)
|
|
207
|
+
|
|
208
|
+

|
|
209
|
+
|
|
210
|
+
<!-- [source_code]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/maps/maps-render-rest -->
|
|
211
|
+
<!-- [npm_package]: https://www.npmjs.com/package/@azure-rest/maps-render -->
|
|
212
|
+
<!-- [api_ref]: https://docs.microsoft.com/javascript/api/@azure-rest/maps-render?view=azure-node-preview -->
|
|
213
|
+
<!-- [samples]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/maps/maps-render-rest/samples -->
|
|
214
|
+
|
|
215
|
+
[product_info]: https://docs.microsoft.com/rest/api/maps/render-v2
|
|
216
|
+
[nodejs_release]: https://nodejs.org/about/releases/
|
|
217
|
+
[az_subscription]: https://azure.microsoft.com/free/
|
|
218
|
+
[az_maps_account_management]: https://docs.microsoft.com/azure/azure-maps/how-to-manage-account-keys
|
|
219
|
+
[azure_portal]: https://portal.azure.com
|
|
220
|
+
[azure_powershell]: https://docs.microsoft.com/powershell/module/az.maps/new-azmapsaccount
|
|
221
|
+
[azure_cli]: https://docs.microsoft.com/cli/azure
|
|
222
|
+
[az_map_pricing]: https://docs.microsoft.com/azure/azure-maps/choose-pricing-tier
|
|
223
|
+
[az_map_az_cli]: https://docs.microsoft.com/cli/azure/maps/account?view=azure-cli-latest#az_maps_account_create
|
|
224
|
+
[az_map_auth]: https://learn.microsoft.com/azure/azure-maps/azure-maps-authentication
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var coreAuth = require('@azure/core-auth');
|
|
6
|
+
var coreRestPipeline = require('@azure/core-rest-pipeline');
|
|
7
|
+
var mapsCommon = require('@azure/maps-common');
|
|
8
|
+
var coreClient = require('@azure-rest/core-client');
|
|
9
|
+
|
|
10
|
+
// Copyright (c) Microsoft Corporation.
|
|
11
|
+
/**
|
|
12
|
+
* Initialize a new instance of the class MapsRenderClient class.
|
|
13
|
+
* @param credentials type: KeyCredential
|
|
14
|
+
*/
|
|
15
|
+
function createClient(credentials, options = {}) {
|
|
16
|
+
var _a, _b;
|
|
17
|
+
const baseUrl = (_a = options.baseUrl) !== null && _a !== void 0 ? _a : `https://atlas.microsoft.com`;
|
|
18
|
+
options.apiVersion = (_b = options.apiVersion) !== null && _b !== void 0 ? _b : "2022-08-01";
|
|
19
|
+
options = Object.assign(Object.assign({}, options), { credentials: {
|
|
20
|
+
apiKeyHeaderName: "subscription-key"
|
|
21
|
+
} });
|
|
22
|
+
const userAgentInfo = `azsdk-js-maps-render-rest/1.0.0-beta.1`;
|
|
23
|
+
const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix
|
|
24
|
+
? `${options.userAgentOptions.userAgentPrefix} ${userAgentInfo}`
|
|
25
|
+
: `${userAgentInfo}`;
|
|
26
|
+
options = Object.assign(Object.assign({}, options), { userAgentOptions: {
|
|
27
|
+
userAgentPrefix
|
|
28
|
+
} });
|
|
29
|
+
const client = coreClient.getClient(baseUrl, credentials, options);
|
|
30
|
+
return client;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Copyright (c) Microsoft Corporation.
|
|
34
|
+
function MapsRender(credential, clientIdOrOptions = {}, maybeOptions = {}) {
|
|
35
|
+
const options = typeof clientIdOrOptions === "string" ? maybeOptions : clientIdOrOptions;
|
|
36
|
+
/**
|
|
37
|
+
* maps service requires a header "ms-x-client-id", which is different from the standard AAD.
|
|
38
|
+
* So we need to do our own implementation.
|
|
39
|
+
* This customized authentication is following by this guide: https://github.com/Azure/azure-sdk-for-js/blob/main/documentation/RLC-customization.md#custom-authentication
|
|
40
|
+
*/
|
|
41
|
+
if (coreAuth.isTokenCredential(credential)) {
|
|
42
|
+
const clientId = typeof clientIdOrOptions === "string" ? clientIdOrOptions : "";
|
|
43
|
+
if (!clientId) {
|
|
44
|
+
throw Error("Client id is needed for TokenCredential");
|
|
45
|
+
}
|
|
46
|
+
const client = createClient(undefined, options);
|
|
47
|
+
client.pipeline.addPolicy(coreRestPipeline.bearerTokenAuthenticationPolicy({
|
|
48
|
+
credential,
|
|
49
|
+
scopes: `${options.baseUrl || "https://atlas.microsoft.com"}/.default`,
|
|
50
|
+
}));
|
|
51
|
+
client.pipeline.addPolicy(mapsCommon.createMapsClientIdPolicy(clientId));
|
|
52
|
+
return client;
|
|
53
|
+
}
|
|
54
|
+
return createClient(credential, options);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Copyright (c) Microsoft Corporation.
|
|
58
|
+
// Licensed under the MIT license.
|
|
59
|
+
const responseMap = {
|
|
60
|
+
"GET /map/tile": ["200"],
|
|
61
|
+
"GET /map/tileset": ["200"],
|
|
62
|
+
"GET /map/attribution": ["200"],
|
|
63
|
+
"GET /map/statetile": ["200"],
|
|
64
|
+
"GET /map/copyright/caption/{format}": ["200"],
|
|
65
|
+
"GET /map/static/{format}": ["200"],
|
|
66
|
+
"GET /map/copyright/bounding/{format}": ["200"],
|
|
67
|
+
"GET /map/copyright/tile/{format}": ["200"],
|
|
68
|
+
"GET /map/copyright/world/{format}": ["200"]
|
|
69
|
+
};
|
|
70
|
+
function isUnexpected(response) {
|
|
71
|
+
const lroOriginal = response.headers["x-ms-original-url"];
|
|
72
|
+
const url = new URL(lroOriginal !== null && lroOriginal !== void 0 ? lroOriginal : response.request.url);
|
|
73
|
+
const method = response.request.method;
|
|
74
|
+
let pathDetails = responseMap[`${method} ${url.pathname}`];
|
|
75
|
+
if (!pathDetails) {
|
|
76
|
+
pathDetails = geParametrizedPathSuccess(method, url.pathname);
|
|
77
|
+
}
|
|
78
|
+
return !pathDetails.includes(response.status);
|
|
79
|
+
}
|
|
80
|
+
function geParametrizedPathSuccess(method, path) {
|
|
81
|
+
var _a, _b;
|
|
82
|
+
const pathParts = path.split("/");
|
|
83
|
+
// Iterate the responseMap to find a match
|
|
84
|
+
for (const [key, value] of Object.entries(responseMap)) {
|
|
85
|
+
// Extracting the path from the map key which is in format
|
|
86
|
+
// GET /path/foo
|
|
87
|
+
if (!key.startsWith(method)) {
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
const candidatePath = getPathFromMapKey(key);
|
|
91
|
+
// Get each part of the url path
|
|
92
|
+
const candidateParts = candidatePath.split("/");
|
|
93
|
+
// If the candidate and actual paths don't match in size
|
|
94
|
+
// we move on to the next candidate path
|
|
95
|
+
if (candidateParts.length === pathParts.length &&
|
|
96
|
+
hasParametrizedPath(key)) {
|
|
97
|
+
// track if we have found a match to return the values found.
|
|
98
|
+
let found = true;
|
|
99
|
+
for (let i = 0; i < candidateParts.length; i++) {
|
|
100
|
+
if (((_a = candidateParts[i]) === null || _a === void 0 ? void 0 : _a.startsWith("{")) &&
|
|
101
|
+
((_b = candidateParts[i]) === null || _b === void 0 ? void 0 : _b.endsWith("}"))) {
|
|
102
|
+
// If the current part of the candidate is a "template" part
|
|
103
|
+
// it is a match with the actual path part on hand
|
|
104
|
+
// skip as the parameterized part can match anything
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
// If the candidate part is not a template and
|
|
108
|
+
// the parts don't match mark the candidate as not found
|
|
109
|
+
// to move on with the next candidate path.
|
|
110
|
+
if (candidateParts[i] !== pathParts[i]) {
|
|
111
|
+
found = false;
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
// We finished evaluating the current candidate parts
|
|
116
|
+
// if all parts matched we return the success values form
|
|
117
|
+
// the path mapping.
|
|
118
|
+
if (found) {
|
|
119
|
+
return value;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
// No match was found, return an empty array.
|
|
124
|
+
return [];
|
|
125
|
+
}
|
|
126
|
+
function hasParametrizedPath(path) {
|
|
127
|
+
return path.includes("/{");
|
|
128
|
+
}
|
|
129
|
+
function getPathFromMapKey(mapKey) {
|
|
130
|
+
const pathStart = mapKey.indexOf("/");
|
|
131
|
+
return mapKey.slice(pathStart);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// Copyright (c) Microsoft Corporation.
|
|
135
|
+
// Licensed under the MIT license.
|
|
136
|
+
function clip(n, minValue, maxValue) {
|
|
137
|
+
return Math.min(Math.max(n, minValue), maxValue);
|
|
138
|
+
}
|
|
139
|
+
const MIN_LATITUDE = -85.05112878;
|
|
140
|
+
const MAX_LATITUDE = 85.05112878;
|
|
141
|
+
const MIN_LONGITUDE = -180;
|
|
142
|
+
const MAX_LONGITUDE = 180;
|
|
143
|
+
/**
|
|
144
|
+
* Calculates the XY tile coordinates that a coordinate falls into for a specific zoom level.
|
|
145
|
+
* Reference: https://learn.microsoft.com/en-us/azure/azure-maps/zoom-levels-and-tile-grid?tabs=typescript#tile-math-source-code
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* ```ts
|
|
149
|
+
* const zoom = 6;
|
|
150
|
+
* const { x, y } = positionToTileXY([47.61559, -122.33817], 6, "256");
|
|
151
|
+
* const response = await client
|
|
152
|
+
* .path("/map/tile")
|
|
153
|
+
* .get({
|
|
154
|
+
* queryParameters: { tilesetId: "microsoft.base.road", zoom, x, y },
|
|
155
|
+
* })
|
|
156
|
+
* ```
|
|
157
|
+
*
|
|
158
|
+
* @param position - Position coordinate in the format [latitude, longitude].
|
|
159
|
+
* @param zoom - Zoom level.
|
|
160
|
+
* @param tileSize - The size of the tiles in the tile pyramid.
|
|
161
|
+
* @returns Tile XY coordinates.
|
|
162
|
+
*/
|
|
163
|
+
function positionToTileXY(position, zoom, tileSize) {
|
|
164
|
+
const latitude = clip(position[0], MIN_LATITUDE, MAX_LATITUDE);
|
|
165
|
+
const longitude = clip(position[1], MIN_LONGITUDE, MAX_LONGITUDE);
|
|
166
|
+
const x = (longitude + 180) / 360;
|
|
167
|
+
const sinLatitude = Math.sin((latitude * Math.PI) / 180);
|
|
168
|
+
const y = 0.5 - Math.log((1 + sinLatitude) / (1 - sinLatitude)) / (4 * Math.PI);
|
|
169
|
+
const tileSizeInNum = parseInt(tileSize);
|
|
170
|
+
// tileSize needed in calculations as in rare cases the multiplying/rounding/dividing can make the difference of a pixel which can result in a completely different tile.
|
|
171
|
+
const mapSize = Math.ceil(tileSizeInNum * Math.pow(2, zoom));
|
|
172
|
+
return {
|
|
173
|
+
x: Math.floor(clip(x * mapSize + 0.5, 0, mapSize - 1) / tileSizeInNum),
|
|
174
|
+
y: Math.floor(clip(y * mapSize + 0.5, 0, mapSize - 1) / tileSizeInNum),
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// Copyright (c) Microsoft Corporation.
|
|
179
|
+
// Licensed under the MIT license.
|
|
180
|
+
/**
|
|
181
|
+
* @internal
|
|
182
|
+
* Workaround to create a path query string for [ collectionFormat: multi ](https://swagger.io/docs/specification/2-0/describing-parameters/#:~:text=csv%20(-,default,-)).
|
|
183
|
+
* This should be removed once the core-client support collectionFormat: multi.
|
|
184
|
+
*/
|
|
185
|
+
function createMultiCollection(key, values) {
|
|
186
|
+
return values.slice(1).reduce((acc, value) => {
|
|
187
|
+
return `${acc}&${key}=${value}`;
|
|
188
|
+
}, values[0] || "");
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// Copyright (c) Microsoft Corporation.
|
|
192
|
+
const optionKeyMap$1 = {
|
|
193
|
+
opacity: "al",
|
|
194
|
+
labelAnchor: "la",
|
|
195
|
+
labelColor: "lc",
|
|
196
|
+
labelSizeInPixels: "ls",
|
|
197
|
+
pinAnchor: "an",
|
|
198
|
+
rotationInDegree: "ro",
|
|
199
|
+
scale: "sc",
|
|
200
|
+
pinColor: "co",
|
|
201
|
+
};
|
|
202
|
+
function isOptionKeyMap(key) {
|
|
203
|
+
return key in optionKeyMap$1;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Create a pin query string for _get map static image_
|
|
207
|
+
*
|
|
208
|
+
* @example
|
|
209
|
+
* ```ts
|
|
210
|
+
*
|
|
211
|
+
* const pins = {
|
|
212
|
+
* pins: [
|
|
213
|
+
* { coordinate: [52.577, 13.35], label: "Label start" },
|
|
214
|
+
* { coordinate: [52.6, 13.2988], label: "Label end" },
|
|
215
|
+
* ],
|
|
216
|
+
* pinImage: "<image source url || default || none>"
|
|
217
|
+
* options: {
|
|
218
|
+
* scale: 0.9,
|
|
219
|
+
* pinColor: "FF0000",
|
|
220
|
+
* labelColor: "0000FF",
|
|
221
|
+
* labelSizeInPixels: 18,
|
|
222
|
+
* }
|
|
223
|
+
* );
|
|
224
|
+
* const res = await client
|
|
225
|
+
* .path("/map/static/{format}", "png")
|
|
226
|
+
* .get({
|
|
227
|
+
* queryParameters: {
|
|
228
|
+
* bbox: [13.228, 52.4559, 13.5794, 52.62],
|
|
229
|
+
* zoom: 10,
|
|
230
|
+
* pins: pins,
|
|
231
|
+
* },
|
|
232
|
+
* skipUrlEncoding: true,
|
|
233
|
+
* })
|
|
234
|
+
* ```
|
|
235
|
+
*
|
|
236
|
+
* @param pins - An array of {@link Pin} that specify the positions and label text of each pin.
|
|
237
|
+
* @param pinImage - Specify the image source for custom pin. Set this to "none" if you don't want to show a pin image.
|
|
238
|
+
* @param options - The style options of the pins. See {@link PinOptions}
|
|
239
|
+
* @returns - The composed query string.
|
|
240
|
+
*/
|
|
241
|
+
function createPinsQuery(pinSets) {
|
|
242
|
+
const pinsQueries = pinSets.map(({ pins, pinImage = "default", options = {} }) => {
|
|
243
|
+
// compose the pins' position query string
|
|
244
|
+
const pinsQueryStr = pins
|
|
245
|
+
.map(({ coordinate: [lat, lon], label }) => `${label ? `'${label}'` : ""}${lon} ${lat}`)
|
|
246
|
+
.join("|");
|
|
247
|
+
// compose the options query string
|
|
248
|
+
const optionsQueryStr = Object.entries(options).reduce((queryStr, [key, val]) => {
|
|
249
|
+
if (!isOptionKeyMap(key))
|
|
250
|
+
throw Error(`Unexpected option: ${key}`);
|
|
251
|
+
if (Array.isArray(val))
|
|
252
|
+
return (queryStr += `|${optionKeyMap$1[key]}${val[0]} ${val[1]}`);
|
|
253
|
+
return (queryStr += `|${optionKeyMap$1[key]}${val}`);
|
|
254
|
+
}, "");
|
|
255
|
+
if (pinImage === "none" || pinImage === "default") {
|
|
256
|
+
return `${pinImage}${optionsQueryStr}||${pinsQueryStr}`;
|
|
257
|
+
}
|
|
258
|
+
return `custom${optionsQueryStr}||${pinsQueryStr}||${pinImage}`;
|
|
259
|
+
});
|
|
260
|
+
return createMultiCollection("pins", pinsQueries);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// Copyright (c) Microsoft Corporation.
|
|
264
|
+
function isCircularPath(path) {
|
|
265
|
+
return "center" in path;
|
|
266
|
+
}
|
|
267
|
+
const optionKeyMap = {
|
|
268
|
+
lineColor: "lc",
|
|
269
|
+
lineOpacity: "la",
|
|
270
|
+
fillColor: "fc",
|
|
271
|
+
fillOpacity: "fa",
|
|
272
|
+
lineWidthInPixels: "lw",
|
|
273
|
+
radius: "ra",
|
|
274
|
+
};
|
|
275
|
+
function isOptionKey(key) {
|
|
276
|
+
return key in optionKeyMap;
|
|
277
|
+
}
|
|
278
|
+
function comosePathVal(coordinates, options) {
|
|
279
|
+
// compose the coordinates query string
|
|
280
|
+
const coordinatesQueryStr = coordinates.map(([lat, lon]) => `${lon} ${lat}`).join("|");
|
|
281
|
+
// compose the options query string
|
|
282
|
+
const optionsQueryStr = Object.entries(options).reduce((queryStr, [key, val]) => {
|
|
283
|
+
if (!isOptionKey(key))
|
|
284
|
+
throw Error(`Unknown key ${key}`);
|
|
285
|
+
queryStr += `${queryStr ? "|" : ""}${optionKeyMap[key]}${val}`;
|
|
286
|
+
return queryStr;
|
|
287
|
+
}, "");
|
|
288
|
+
return optionsQueryStr + "||" + coordinatesQueryStr;
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Create a path query string for _get map static image_ request.
|
|
292
|
+
*
|
|
293
|
+
* @example
|
|
294
|
+
* ```ts
|
|
295
|
+
* const circularPath = {
|
|
296
|
+
* center: [52.4559, 13.228],
|
|
297
|
+
* radiusInMeters: 10000,
|
|
298
|
+
* options: {
|
|
299
|
+
* lineColor: "000000",
|
|
300
|
+
* lineOpacity: 0.9,
|
|
301
|
+
* lineWidthInPixels: 2,
|
|
302
|
+
* },
|
|
303
|
+
* };
|
|
304
|
+
*
|
|
305
|
+
* const linearPath = {
|
|
306
|
+
* coordinates: [
|
|
307
|
+
* [52.577, 13.35],
|
|
308
|
+
* [52.6, 13.2988],
|
|
309
|
+
* [52.32, 13.2988],
|
|
310
|
+
* ],
|
|
311
|
+
* options: {
|
|
312
|
+
* lineColor: "000000",
|
|
313
|
+
* lineOpacity: 0.9,
|
|
314
|
+
* lineWidthInPixels: 2,
|
|
315
|
+
* },
|
|
316
|
+
* };
|
|
317
|
+
*
|
|
318
|
+
* const polygonPath = {
|
|
319
|
+
* coordinates: [
|
|
320
|
+
* [52.577, 13.35],
|
|
321
|
+
* [52.6, 13.2988],
|
|
322
|
+
* [52.32, 13.2988],
|
|
323
|
+
* [52.577, 13.35],
|
|
324
|
+
* ],
|
|
325
|
+
* options: {
|
|
326
|
+
* lineColor: "000000",
|
|
327
|
+
* lineOpacity: 0.9,
|
|
328
|
+
* lineWidthInPixels: 2,
|
|
329
|
+
* fillColor: "FFFFFF",
|
|
330
|
+
* fillOpacity: 0.8,
|
|
331
|
+
* },
|
|
332
|
+
* };
|
|
333
|
+
*
|
|
334
|
+
* const path = createPathQuery([circularPath, linearPath, polygonPath]);
|
|
335
|
+
* // Send the request
|
|
336
|
+
* const response = await client.path("/map/static/{format}", "png").get({
|
|
337
|
+
* queryParameters: {
|
|
338
|
+
* bbox: [13.228,52.4559,13.5794,52.629],
|
|
339
|
+
* path: path
|
|
340
|
+
* }
|
|
341
|
+
* });
|
|
342
|
+
* ```
|
|
343
|
+
*
|
|
344
|
+
* @param paths - A collection of {@link PolygonalPath} and {@link CircularPath} that you want to draw on the image.
|
|
345
|
+
* @param options - The options for the style of the path. See the possible options in {@link PolygonalPathOptions} and {@link CircularPathOptions}.
|
|
346
|
+
*/
|
|
347
|
+
function createPathQuery(paths) {
|
|
348
|
+
const pathQueries = paths.map((path) => {
|
|
349
|
+
if (isCircularPath(path)) {
|
|
350
|
+
const { center, radiusInMeters, options } = path;
|
|
351
|
+
return comosePathVal([center], Object.assign(Object.assign({}, options), { radius: radiusInMeters }));
|
|
352
|
+
}
|
|
353
|
+
return comosePathVal(path.coordinates, path.options || {});
|
|
354
|
+
});
|
|
355
|
+
return createMultiCollection("path", pathQueries);
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
// Copyright (c) Microsoft Corporation.
|
|
359
|
+
|
|
360
|
+
exports.createPathQuery = createPathQuery;
|
|
361
|
+
exports.createPinsQuery = createPinsQuery;
|
|
362
|
+
exports["default"] = MapsRender;
|
|
363
|
+
exports.isUnexpected = isUnexpected;
|
|
364
|
+
exports.positionToTileXY = positionToTileXY;
|
|
365
|
+
//# sourceMappingURL=index.js.map
|