JSFiddle - React, Tailwind, and code Playground
HTML
<script src="http://cdn.leafletjs.com/leaflet-0.4.5/leaflet.js"></script>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.4.5/leaflet.css">
<b>A Map using Leaflet.js</b>
<div id="mymap" style="width:450px;height:430px;"></div>
CSS
html, body{ width:100%; height: 100%, margin:0; padding:0; }
#mymap{ width:100%; height:100%; }
JavaScript
// create a map
map = new L.Map('mymap');
// create the OpenStreetMap layer
osmTile = "http://tile.openstreetmap.org/{z}/{x}/{y}.png";
osmCopyright = "Map data © 2012 OpenStreetMap contributors";
osmLayer = new L.TileLayer(osmTile, { maxZoom: 18, attribution: osmCopyright } );
map.addLayer(osmLayer);
// set the map's starting view
map.setView( new L.LatLng(42.360752, -71.05), 15 );
var buildings = [
{
name: "Boston Aquarium",
lonlats: [
[-71.048501,42.359521],
[-71.048439,42.359293],
[-71.0486,42.359277],
[-71.048541,42.359069],
[-71.049362,42.358968],
[-71.050164,42.359261]
],
video:"http://www.youtube.com/embed/HZkauzLKm2c"
},
{
name: "Boston City Hall",
lonlats: [
[-71.058465,42.360752],
[-71.057561,42.360823],
[-71.057408,42.359965],
[-71.058326,42.359884]
],
video: "http://www.youtube.com/embed/q5poo1sdNHg"
}
];
for(i=0;i<buildings.length;i=i+1){
// inside of this loop - runs for each building
var latlngs = [ ];
for(j=0;j<=buildings[i].lonlats.length-1;j=j+1){
//inside of this loop, convert lonlat to L.LatLng
//runs for each point in each building
latlngs.push( new L.LatLng(buildings[i].lonlats[j][1], buildings[i].lonlats[j][0]) );
}
// now that we have a list of points, turn the building into a polygon
buildingPolygon = new L.Polygon(latlngs, { color: 'green', fillColor: 'red' });
buildingPolygon.bindPopup("<h3>" + buildings[i].name + "</h3><iframe src='" + buildings[i].video + "' width='260' height='220' frameborder='0' allowfullscreen></iframe>");
// add attributes
buildingPolygon.attributes = {
name: buildings[i].name,
video: buildings[i].video
};
map.addLayer(buildingPolygon);
}