Leaflet/examples/geojson-example.html

46 lines
1.5 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<title>Leaflet GeoJSON example</title>
<link rel="stylesheet" href="../dist/leaflet.css" />
<!--[if lte IE 8]><link rel="stylesheet" href="../dist/leaflet.ie.css" /><![endif]-->
<script src="../dist/leaflet.js"></script>
<script src="sample-geojson.js" type="text/javascript"></script>
</head>
<body>
<div id="map" style="width: 600px; height: 400px"></div>
<script>
var map = new L.Map('map');
var cloudmadeUrl = 'http://{s}.tile.cloudmade.com/BC9A493B41014CAABB98F0471D759707/22677/256/{z}/{x}/{y}.png',
cloudmadeAttribution = 'Map data &copy; 2011 OpenStreetMap contributors, Imagery &copy; 2011 CloudMade',
cloudmade = new L.TileLayer(cloudmadeUrl, {maxZoom: 18, attribution: cloudmadeAttribution});
map.setView(new L.LatLng(39.74402223643582, -104.99264717102051), 14)
.addLayer(cloudmade);
var geojson_layer = new L.GeoJSON();
geojson_layer.on( "featureparse", function( e ) {
var popup_content = "<p>I started out as a GeoJSON " + e.geometryType + ", but now I'm a Leaflet vector!</p>";
if ( e.properties && e.properties.popup_content ) {
popup_content += e.properties.popup_content;
}
e.layer.bindPopup( popup_content );
if ( e.properties && e.properties.style ) {
e.layer.setStyle( e.properties.style );
}
} );
map.addLayer( geojson_layer );
geojson_layer.addGeoJSON( free_bus );
geojson_layer.addGeoJSON( bicycle_rental );
geojson_layer.addGeoJSON( campus );
</script>
</body>
</html>