Add a GeoJSON line
Add a GeoJSON line to a map using addSource
, then style it using addLayer
’s paint
properties.
<!DOCTYPE html><html><head><meta charset="utf-8" /><title>Add a GeoJSON line</title><meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" /><script src="https://cdn.jsdelivr.net/npm/@goongmaps/goong-js@1.0.9/dist/goong-js.js"></script><link href="https://cdn.jsdelivr.net/npm/@goongmaps/goong-js@1.0.9/dist/goong-js.css" rel="stylesheet" /><style> body { margin: 0; padding: 0; } #map { position: absolute; top: 0; bottom: 0; width: 100%; }</style></head><body><div id="map"></div><script>goongjs.accessToken = '8qzxZAuxcsctSlmOszInchP1A5GrmRBHJwCBCjO6';var map = new goongjs.Map({container: 'map',style: 'https://tiles.goong.io/assets/goong_map_web.json',center: [105.84910869598389, 21.029451894670853],zoom: 15}); map.on('load', function () {map.addSource('route', {'type': 'geojson','data': {'type': 'Feature','properties': {},'geometry': {'type': 'LineString','coordinates': [[105.84752082824707, 21.031514816640872],[105.8529281616211, 21.031514816640872],[105.85279941558838, 21.027489088033935],[105.84707021713255, 21.026607819503038],[105.8446455001831, 21.02953200867838],[105.84593296051025, 21.03159492953939]]}}});map.addLayer({'id': 'route','type': 'line','source': 'route','layout': {'line-join': 'round','line-cap': 'round'},'paint': {'line-color': '#888','line-width': 8}});});</script> </body></html>