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/04-draw-a-line-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 Line on Map

To draw a line on the map:

// use maplibre addSource and addLayer function
const sourceId = 'myLine';
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: 'LineString',
        coordinates: coordinates
      }
    }
  });
}
function addLayer() {
  maplibreMap.addLayer({
    id: layerId,
    type: 'line',
    source: sourceId,
    layout: {
      'line-join': 'round',
      'line-cap': 'round'
    },
    paint: {
      'line-color': '#007cbf',
      'line-width': 8
    }
  });
}

Sample web page: