Converts a Google Maps styler array to a Google Static Maps styler URL query string.
For Node.js, to install google-static-maps-styler-query with npm, run:
npm install google-static-maps-styler-queryFor browsers, an example import map:
{
"imports": {
"google-static-maps-styler-query": "https://unpkg.com/google-static-maps-styler-query@6.0.0/googleStaticMapsStylerQuery.mjs"
}
}Then, import and use the function googleStaticMapsStylerQuery.
How to create a styled static map URL:
import googleStaticMapsStylerQuery from "google-static-maps-styler-query";
const styles = [{ elementType: "labels", stylers: [{ visibility: "off" }] }];
const stylerQuery = googleStaticMapsStylerQuery(styles);
const googleStaticMapSrc = `https://maps.googleapis.com/maps/api/staticmap?center=Australia&size=250x200${stylerQuery}`;Supported runtime environments:
- Node.js versions
^14.17.0 || ^16.0.0 || >= 18.0.0. - Browsers matching the Browserslist query
> 0.5%, not OperaMini all, not dead.
Projects must configure TypeScript to use types from the ECMAScript modules that have a // @ts-check comment:
compilerOptions.allowJsshould betrue.compilerOptions.maxNodeModuleJsDepthshould be reasonably large, e.g.10.compilerOptions.moduleshould be"node16"or"nodenext".
The npm package google-static-maps-styler-query features optimal JavaScript module design. These ECMAScript modules are exported via the package.json field exports: