For AI agents: the complete documentation index is available at /core-sdk/map/web/llms.txt, the full documentation bundle is available at /core-sdk/map/web/llms-full.txt, and this page is available as Markdown at /core-sdk/map/web/v10/10-markers-annotations/05-draw-a-polygon-on-map.md.
MapxusDeveloper Platform
Products
Positioning APIAccess real-time indoor coordinates and contextual signals.API
UI SDKProduction-ready indoor map interfaces and UI components.AndroidiOS

Draw a Polygon on Map

To draw a polygon on the map:

// use maplibre addSource and addLayer function
const sourceId = 'myArea';
const layerId = sourceId + 'Layer';
const coordinates = [
  [
    [114.16139, 22.30704],
    [114.15964, 22.30312],
    [114.16059, 22.30289],
    [114.1634, 22.303],
    [114.16352, 22.30652]
  ]
];
// init maplibre-gl map
const maplibreMap = new maplibregl.Map({
    container: 'map'
});

function addSource() {
  maplibreMap.addSource(sourceId, {
    type: 'geojson',
    data: {
      type: 'Feature',
      geometry: {
        type: 'Polygon',
        coordinates: coordinates
      }
    }
  });
}
function addLayer() {
  maplibreMap.addLayer({
    id: layerId,
    type: 'fill',
    source: sourceId,
    layout: {},
    paint: {
      'fill-color': '#007cbf',
      'fill-outline-color': '#ffffcc'
    }
  });
}

Sample web page: