Using Typescript

Using TypeScript with Woosmap Map JS API

  1. Overview
  2. Getting Started

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 Command
Shell
        npm i -D @types/woosmap.map

    

Or through your package dependencies:

package.json
JSON
        "devDependencies": {
  "@types/woosmap.map": "~1.4.1",
}

    

And here is a basic example on how to create a Map:

Create a Map using Typescript
typescript
        let map: woosmap.map.Map;
const initialCenter: woosmap.map.LatLngLiteral = {lat: 42.3, lng: 2.4};
const initialZoom: number = 7;

function initMap(): void {
    map = new woosmap.map.Map(document.getElementById("map") as HTMLElement, {
        initialCenter,
        initialZoom
    });
}

    

To help you build your locator using Typescript and Map JS API, feel free to look at this sample application on GitHub.

Was this article helpful?
Have more questions? Submit a request