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://unpkg.com/trackasia-gl@1.0.5/dist/trackasia-gl.js"></script><link href="https://unpkg.com/trackasia-gl@1.0.5/dist/trackasia-gl.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>
var map = new trackasiagl.Map({
container: 'map',
style: 'https://maps.track-asia.com/styles/v1/streets.json?key=public_key',
center: [106.720772,10.77423],
zoom: 14
});
map.on('load', function () {
map.addSource('route', {
'type': 'geojson',
'data': {
'type': 'Feature',
'properties': {},
'geometry': {
'type': 'LineString',
'coordinates': [[106.716666,10.771724],[106.716387,10.773832],[106.717031,10.775835],[106.714176,10.777268],[106.715164,10.778638],[106.716087,10.777964],[106.717075,10.77887],[106.718341,10.777247],[106.722206,10.778491],[106.72255,10.776657],[106.722271,10.774528],[106.72255,10.773463],[106.732306,10.778378]]
}
}
});
map.addLayer({
'id': 'route',
'type': 'line',
'source': 'route',
'layout': {
'line-join': 'round',
'line-cap': 'round'
},
'paint': {
'line-color': 'red',
'line-width': 6
}
});
});
</script>
</body></html>