Using Typescript
Using TypeScript with Woosmap Map JS API
Overview
TypeScript is a strongly typed programming language that compiles to plain JavaScript. Typing your code allows to catch errors early in your editor and makes it incomparably easier to understand and maintain.
The Woosmap Map JS API has dedicated Typescript typings published on DefinitelyTyped. The DefinitelyTyped project is an open source project that maintains type declaration files for many packages including Woosmap Map. The Woosmap Map JavaScript declaration files ( see source files on GitHub) are published as @types/woosmap.map package on NPM.
These TypeScript definitions are generated directly from the API source code, bringing you the most accurate up-to-date TypeScript definitions for the Map JS API to use in your web apps.
Getting Started
To start using it, install the types with the following command:
npm i -D @types/woosmap.map
Or through your package dependencies:
"devDependencies": {
"@types/woosmap.map": "^1.4.28"
}
Here is a basic example that centers the map of a <wmp-map id="map"> element, on a page that includes the bootstrap loader:
const center: woosmap.map.LatLngLiteral = { lat: 42.3, lng: 2.4 };
async function initMap(): Promise<void> {
await woosmap.map.importLibrary("maps");
const map = (document.getElementById("map") as woosmap.map.MapElement).innerMap;
map.moveCamera({ center, zoom: 7 });
}
initMap();
To help you build your locator using Typescript and Map JS API, feel free to look at this sample application on GitHub.