block by majomo fffd7f7e07c441cb401f

Leaflet Map with a Polygon - Vancouver

Full Screen

index.html

<!DOCTYPE html>

<html>

<head>
<script src="https://code.jquery.com/jquery-2.1.4.js"></script>

<title>Leaflet Web Map</title>

<!-- reference to Leaflet CSS -->
<link rel="stylesheet" href="//cdn.leafletjs.com/leaflet-0.7.3/leaflet.css" />

<!-- reference to Leaflet JavaScript -->
<script src="//cdn.leafletjs.com/leaflet-0.7.3/leaflet.js"></script>

<!-- set width and height styles for map -->
<style>
#map {
    width: 960px;
    height:500px;
}
</style>

</head>

<body>

    <!-- place holder for map -->
    <div id="map"></div>

<script>

    // create map object, tell it to live in 'map' div and give initial latitude, longitude, zoom values
    // pass option to turn scroll wheel zoom off
    var map = L.map('map',{scrollWheelZoom:false}).setView([49.2609,-123.1140], 15);

    // add base map tiles from OpenStreetMap and attribution info to 'map' div
    L.tileLayer('//{s}.tile.osm.org/{z}/{x}/{y}.png', {
    attribution: '&copy; <a href="//osm.org/copyright">OpenStreetMap</a> contributors'
    }).addTo(map);
    
    // define array of points for polygon
    var area = [ [49.2609,-123.1140],[49.260727, -123.126545],[49.265993, -123.126416] ];

    // add polygon from area array points to map with some basic styling
    L.polygon(area,{color:'purple',opacity:.6}).addTo(map);

</script>

</body>

</html>