Skip to content

Add a GeoJSON polygon

Style a polygon with the fill layer type.

<!DOCTYPE html>
<html lang="en">
<head>
    <title>Add a GeoJSON polygon</title>
    <meta property="og:description" content="Style a polygon with the fill layer type." />
    <meta charset='utf-8'>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/trackasia-gl.css" />
    <script src="https://unpkg.com/[email protected]/dist/trackasia-gl.js"></script>
    <style>
        body { margin: 0; padding: 0; }
        html, body, #map { height: 100%; }
    </style>
</head>
<body>
    <div id="map"></div>
<script>
    const map = new trackasiagl.Map({
        container: 'map',
        style: 'https://maps.track-asia.com/styles/v2/streets.json?key=public_key',
        center: [105.101562,9.065754],
        zoom: 8
    });

    map.on('load', () => {
        map.addSource('maine', {
            'type': 'geojson',
            'data': {
                'type': 'Feature',
                'geometry': {
                    'type': 'Polygon',
                    'coordinates': [[[104.711292,8.615239],[104.859705,8.560923],[105.107058,8.62067],[105.260967,8.761852],[105.418234,9.008928],[105.249698,9.087452],[105.278247,9.16423],[105.274811,9.184227],[105.261087,9.179143],[105.235451,9.224522],[105.297289,9.280095],[105.249193,9.323462],[105.298664,9.384439],[105.010166,9.552407],[104.944205,9.533447],[104.919469,9.551052],[104.882366,9.492814],[104.839767,9.521257],[104.787999,8.778139],[104.903057,8.804061],[104.791748,8.713124],[104.797245,8.653391],[104.72029,8.647961],[104.711292,8.615239]]]
                }
            }
        });
        map.addLayer({
            'id': 'maine',
            'type': 'fill',
            'source': 'maine',
            'layout': {},
            'paint': {
                'fill-color': '#088',
                'fill-opacity': 0.8
            }
        });
    });
</script>

</body>
</html>