Get Started

Get started with the Woosmap Map JavaScript API. View a simple example, learn the concepts, and create custom maps for your site.

The Woosmap Map JavaScript API allows you to embed interactive maps on web pages.

API Key
Woosmap Map JS API requires authorization via API Key for initialization and API calls. You can obtain it by following this steps.

Overview

You can use this JavaScript API to embed interactive maps directly into your webpages. You can also add stores overlay to the map to call out points of interest and get relative information.

Here is a basic Woosmap Map sample centered on London.

Add a simple map
        // Initialize and add the map
let map: woosmap.map.Map;

async function initMap(): Promise<void> {
  await woosmap.map.importLibrary("maps");

  // The location of London
  const position: woosmap.map.LatLngLiteral = {
    lat: 51.50940214,
    lng: -0.133012,
  };

  // The map, centered at London
  map = (document.getElementById("map") as woosmap.map.MapElement).innerMap;
  map.moveCamera({
    zoom: 13,
    center: position,
  });
}

initMap();

    
        // Initialize and add the map
let map;

async function initMap() {
  await woosmap.map.importLibrary("maps");

  // The location of London
  const position = {
    lat: 51.50940214,
    lng: -0.133012,
  };

  // The map, centered at London
  map = document.getElementById("map").innerMap;
  map.moveCamera({
    zoom: 13,
    center: position,
  });
}

initMap();

    
        /*
 * Always set the map height explicitly to define the size of the element
 * that contains the map. `display: block` is required for <wmp-map>/<gmp-map>,
 * which default to inline like any other custom element outside a flex/grid
 * container (no-op for a plain <div>).
 */
#map {
  display: block;
  width: 100%;
  height: 100%;
}

/*
 * Optional: Makes the sample page fill the window.
 */
html,
body {
  height: 100%;
  margin: 0;
  padding: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Helvetica Neue, Arial, Noto Sans, sans-serif, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol, Noto Color Emoji;
}


    
        <html>
  <head>
    <title>Add Map</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta charset="utf-8" />

    <link rel="stylesheet" type="text/css" href="./style.css" />
    <script type="module" src="./index.js"></script>
  </head>
  <body>
    <!--The div element for the map -->
    <wmp-map id="map"></wmp-map>

    <script>
      (g=>{var p,w=window,d=document,l="importLibrary",q="__ib__",e="The Woosmap Maps JavaScript API",o=w.woosmap||(w.woosmap={}),m=o.map||(o.map={}),r=new Set(String(g.libraries||"").split(",").filter(Boolean)),s=new URLSearchParams,u=()=>p||(p=new Promise((f,n)=>{var a=d.createElement("script");s.set("libraries",[...r]+"");for(var k in g)k!="libraries"&&g[k]&&s.set(k,g[k]);s.set("callback","woosmap.map."+q);a.src="https://sdk.woosmap.com/map/map.js?"+s;m[q]=f;a.onerror=()=>n(Error(e+" could not load."));a.nonce=d.querySelector("script[nonce]")?.nonce||"";d.head.append(a)}));m[l]?console.warn(e+" only loads once. Ignoring:",g):m[l]=(f,...n)=>r.add(f)&&u().then(()=>m[l](f,...n))})({
        key: "woos-e1e5490b-19d1-34f8-9955-fd5cfc8c880f",
      });
    </script>
  </body>
</html>

    

The above code does three things:

  1. It adds a <wmp-map> element to hold the map, with an explicit height set in CSS.

  2. It loads the Map JavaScript API with the inline bootstrap loader.

  3. It loads the maps library in an async initMap() function, then centers the map through the element’s innerMap property.

Loading the Woosmap Map JavaScript API

Add the bootstrap loader once per page, before any script that uses the API. It defines woosmap.map.importLibrary() and fetches map.js the first time you call it.

HTML
        <script>
  (g=>{var p,w=window,d=document,l="importLibrary",q="__ib__",e="The Woosmap Maps JavaScript API",o=w.woosmap||(w.woosmap={}),m=o.map||(o.map={}),r=new Set(String(g.libraries||"").split(",").filter(Boolean)),s=new URLSearchParams,u=()=>p||(p=new Promise((f,n)=>{var a=d.createElement("script");s.set("libraries",[...r]+"");for(var k in g)k!="libraries"&&g[k]&&s.set(k,g[k]);s.set("callback","woosmap.map."+q);a.src="https://sdk.woosmap.com/map/map.js?"+s;m[q]=f;a.onerror=()=>n(Error(e+" could not load."));a.nonce=d.querySelector("script[nonce]")?.nonce||"";d.head.append(a)}));m[l]?console.warn(e+" only loads once. Ignoring:",g):m[l]=(f,...n)=>r.add(f)&&u().then(()=>m[l](f,...n))})({
    key: "YOUR_API_KEY",
    // Add other bootstrap parameters as needed: language, libraries.
  });
</script>

    

Copy the loader as is and set its parameters in the object passed to it.

Required parameter:

  • key: your Woosmap public API key.

Optional parameters:

  • language: the language code for localized content, such as fr.
  • libraries: a comma-separated list of libraries to load with map.js, such as widgets.

Then load the libraries your code needs. importLibrary() returns a promise that resolves once the library is ready.

JavaScript
        await woosmap.map.importLibrary("maps");
await woosmap.map.importLibrary("marker");

    
Library Contents
maps Map, LatLng, InfoWindow, the services and the rest of the core API
marker AdvancedMarkerElement and PinElement
drawing The Drawing tools

The widgets, such as the Indoor Widget, don’t load through importLibrary(). List them in the loader’s libraries parameter instead, for example libraries: "widgets".

Script Tag with a Callback

The classic script tag still works. map.js calls the global function named in callback once the API is ready, and libraries go in the URL:

HTML
        <script defer src="https://sdk.woosmap.com/map/map.js?key=YOUR_API_KEY&callback=initMap"></script>

    

Add the Map Element

The <wmp-map> element holds the map. Give it an id so your code can find it, and an explicit height. Like any custom element, it displays inline by default, so set display: block as well.

HTML
        <wmp-map id="map"></wmp-map>

    
CSS
        #map {
  display: block;
  height: 400px;
}

    

Once the maps library has loaded, the element’s innerMap property returns its woosmap.map.Map.

JavaScript
        await woosmap.map.importLibrary("maps");
const map = document.getElementById("map").innerMap;

    

To draw the map in a container you manage yourself, such as a <div>, pass the element and its options to the constructor: new woosmap.map.Map(element, { center, zoom }).

Define Map Options

Set the initial view with moveCamera():

JavaScript
        map.moveCamera({
  center: { lat: 51.50940214, lng: -0.133012 },
  zoom: 13,
});

    
  • center is the initial map center, as latitude and longitude.
  • zoom is the initial resolution, between 1 (World) and 21 (Buildings).

The other MapOptions go through setOptions(). To start on satellite imagery with a Map/Satellite toggle control:

JavaScript
        map.setOptions({
  mapTypeId: woosmap.map.MapTypeId.HYBRID,
  mapTypeControl: true,
});

    

See Map Types for more details on switching between roadmap and satellite views.

Vector Map

The Map JavaScript API renders vector-based tiles, which are drawn at load time on the client-side using WebGL. It offers a smoother pan and zoom navigation and the high sharpness of vector-based images. In addition, this technology allow the display of 3D buildings at close zoom levels.

In the below sample, toggle the “Buildings” switch to enter the 3D Mode (you can also use the combination of ctrl+click and move your mouse to tilt and rotate the map)

To Go Further

Was this helpful?