Leaflet Polygon

Bagaimana cara membuat polygon dengan menggunakan leaflet. (Leaflet adalah media interaktif maps). Jadi dalam map ada beberapa garis-garis yang menutupi area tertentu. Polygon di buat dari titik-titik yang terhubung. Jadi kuncinya adalah titik koordinat dari latitude longitude nya.

window.onload = function(){
// We’ll add a OSM tile layer to our map
var osmUrl = 'http://{s}.tile.osm.org/{z}/{x}/{y}.png',
osmAttrib = '© OpenStreetMap contributors',
osm = L.tileLayer(osmUrl, {
maxZoom: 18,
attribution: osmAttrib
});

// initialize the map on the "map" div with a given center and zoom
var map = L.map('map').setView([25.92, 79.84], 5).addLayer(osm);

// create a red polygon from an array of LatLng points
var latlngs = [[37, -109.05],[41, -109.03],[41.236511201246216, -105.27099609375],[41, -102.05],[37, -102.04]];
var polygon = L.polygon(latlngs, {color: 'red'}).addTo(map);
// zoom the map to the polygon
map.fitBounds(polygon.getBounds());
}

Output tampilan yang dihasilkan seperti berikut.

leaflet-library-css-js-8

Semoga bermanfaat, wassalam.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s