@azure-rest/maps-render
Version:
A generated SDK for MapsRenderClient.
117 lines • 3.63 kB
JavaScript
;
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
exports.createPathQuery = createPathQuery;
const createMultiCollection_js_1 = require("./createMultiCollection.js");
function isCircularPath(path) {
return "center" in path;
}
const optionKeyMap = {
lineColor: "lc",
lineOpacity: "la",
fillColor: "fc",
fillOpacity: "fa",
lineWidthInPixels: "lw",
radius: "ra",
};
function isOptionKey(key) {
return key in optionKeyMap;
}
function comosePathVal(coordinates, options) {
// compose the coordinates query string
const coordinatesQueryStr = coordinates.map(([lat, lon]) => `${lon} ${lat}`).join("|");
// compose the options query string
const optionsQueryStr = Object.entries(options).reduce((queryStr, [key, val]) => {
if (!isOptionKey(key))
throw Error(`Unknown key ${key}`);
queryStr += `${queryStr ? "|" : ""}${optionKeyMap[key]}${val}`;
return queryStr;
}, "");
return optionsQueryStr + "||" + coordinatesQueryStr;
}
/**
* Create a path query string for _get map static image_ request.
*
* @example
* ```ts snippet:ReadmeSampleCreatePathQuery
* import { DefaultAzureCredential } from "@azure/identity";
* import MapsRender, { CircularPath, PolygonalPath, createPathQuery } from "@azure-rest/maps-render";
* import { createWriteStream } from "node:fs";
*
* const credential = new DefaultAzureCredential();
* const client = MapsRender(credential, "<maps-account-client-id>");
*
* const circularPath: CircularPath = {
* center: [52.4559, 13.228],
* radiusInMeters: 10000,
* options: {
* lineColor: "000000",
* lineOpacity: 0.9,
* lineWidthInPixels: 2,
* },
* };
*
* const linearPath: PolygonalPath = {
* coordinates: [
* [52.577, 13.35],
* [52.6, 13.2988],
* [52.32, 13.2988],
* ],
* options: {
* lineColor: "000000",
* lineOpacity: 0.9,
* lineWidthInPixels: 2,
* },
* };
*
* const polygonPath: PolygonalPath = {
* coordinates: [
* [52.577, 13.35],
* [52.6, 13.2988],
* [52.32, 13.2988],
* [52.577, 13.35],
* ],
* options: {
* lineColor: "000000",
* lineOpacity: 0.9,
* lineWidthInPixels: 2,
* fillColor: "FFFFFF",
* fillOpacity: 0.8,
* },
* };
*
* const path = createPathQuery([circularPath, linearPath, polygonPath]);
* // Send the request
* const response = await client
* .path("/map/static")
* .get({
* queryParameters: {
* bbox: [13.228, 52.4559, 13.5794, 52.629],
* path,
* },
* })
* .asNodeStream();
*
* // Handle the error.
* if (!response.body) {
* throw Error("No response body");
* }
*
* response.body.pipe(createWriteStream("path.png"));
* ```
*
* @param paths - A collection of {@link PolygonalPath} and {@link CircularPath} that you want to draw on the image.
* @param options - The options for the style of the path. See the possible options in {@link PolygonalPathOptions} and {@link CircularPathOptions}.
*/
function createPathQuery(paths) {
const pathQueries = paths.map((path) => {
if (isCircularPath(path)) {
const { center, radiusInMeters, options } = path;
return comosePathVal([center], Object.assign(Object.assign({}, options), { radius: radiusInMeters }));
}
return comosePathVal(path.coordinates, path.options || {});
});
return (0, createMultiCollection_js_1.createMultiCollection)("path", pathQueries);
}
//# sourceMappingURL=createPathQuery.js.map