Leaflet/examples/geojson-example.html

86 lines
2.8 KiB
HTML
Raw Normal View History

2011-06-18 00:45:04 +08:00
<!DOCTYPE html>
<html>
<head>
<title>Leaflet GeoJSON example</title>
2011-06-18 00:45:04 +08:00
<link rel="stylesheet" href="../dist/leaflet.css" />
<!--[if lte IE 8]><link rel="stylesheet" href="../dist/leaflet.ie.css" /><![endif]-->
2011-06-18 00:45:04 +08:00
<script src="../dist/leaflet.js"></script>
2011-09-28 09:20:16 +08:00
<!--<script src="../debug/leaflet-include.js"></script>-->
<script src="sample-geojson.js" type="text/javascript"></script>
2011-06-18 00:45:04 +08:00
</head>
<body>
<div id="map" style="width: 600px; height: 400px"></div>
2011-06-18 00:45:04 +08:00
<script>
var map = new L.Map('map');
var cloudmadeUrl = 'http://{s}.tile.cloudmade.com/BC9A493B41014CAABB98F0471D759707/22677/256/{z}/{x}/{y}.png',
2011-06-18 00:45:04 +08:00
cloudmadeAttribution = 'Map data &copy; 2011 OpenStreetMap contributors, Imagery &copy; 2011 CloudMade',
cloudmade = new L.TileLayer(cloudmadeUrl, {maxZoom: 18, attribution: cloudmadeAttribution});
2011-09-28 09:20:16 +08:00
map.setView(new L.LatLng(39.74738794765598, -105.00002861022949), 14)
.addLayer(cloudmade);
2011-09-28 09:20:16 +08:00
var BaseballIcon = L.Icon.extend({
iconUrl: 'baseball-marker.png',
shadowUrl: null,
iconSize: new L.Point(32, 37),
shadowSize: null,
iconAnchor: new L.Point(14, 37),
popupAnchor: new L.Point(2, -32)
});
2011-09-28 09:20:16 +08:00
var geojson_layer = new L.GeoJSON( null, {
pointToLayer: function ( latlng ) {
return new L.CircleMarker( latlng, {
radius: 8,
fillColor: "#ff7800",
color: "#000",
weight: 1,
opacity: 1,
fillOpacity: 0.8
} );
}
} );
var another_geojson_layer = new L.GeoJSON( coors_field, {
pointToLayer: function ( latlng ) {
return new L.Marker( latlng, {
icon: new BaseballIcon()
} );
}
} );
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 );
}
} );
2011-09-28 09:20:16 +08:00
another_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 );
} );
map.addLayer( geojson_layer ).addLayer( another_geojson_layer );
geojson_layer.addGeoJSON( free_bus );
geojson_layer.addGeoJSON( bicycle_rental );
2011-09-28 09:20:16 +08:00
geojson_layer.addGeoJSON( campus );
another_geojson_layer.addGeoJSON( coors_field );
2011-06-18 00:45:04 +08:00
</script>
</body>
</html>