108 lines
4.1 KiB
HTML
108 lines
4.1 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<title>Leaflet GeoJSON example</title>
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
|
<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="../debug/leaflet-include.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 © 2011 OpenStreetMap contributors, Imagery © 2011 CloudMade',
|
|
cloudmade = new L.TileLayer(cloudmadeUrl, {maxZoom: 18, attribution: cloudmadeAttribution});
|
|
|
|
map.setView(new L.LatLng(39.747, -105), 14).addLayer(cloudmade);
|
|
|
|
var BaseballIcon = L.Icon.extend({
|
|
options: {
|
|
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)
|
|
}
|
|
});
|
|
|
|
var geojsonLayer = 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 anotherGeojsonLayer = new L.GeoJSON(coorsField, {
|
|
pointToLayer: function (latlng){
|
|
return new L.Marker(latlng, {
|
|
icon: new BaseballIcon()
|
|
});
|
|
}
|
|
});
|
|
|
|
var lightRailGeojsonLayer = new L.GeoJSON();
|
|
|
|
geojsonLayer.on("featureparse", function (e) {
|
|
var popupContent = "<p>I started out as a GeoJSON " + e.geometryType + ", but now I'm a Leaflet vector!</p>";
|
|
if (e.geometryType == "Point") {
|
|
popupContent += "<p>This GeoJSON Point has been transformed into a <a href='http://leaflet.cloudmade.com/reference.html#circlemarker'>CircleMarker</a> by passing a <code>pointToLayer</code> function in the <a href='http://leaflet.cloudmade.com/reference.html#geojson-options'>GeoJSON options</a> when instantiating the GeoJSON layer. View source for details.</p>";
|
|
}
|
|
if (e.properties && e.properties.popupContent) {
|
|
popupContent += e.properties.popupContent;
|
|
}
|
|
e.layer.bindPopup(popupContent);
|
|
if (e.properties && e.properties.style && e.layer.setStyle) {
|
|
e.layer.setStyle(e.properties.style);
|
|
}
|
|
});
|
|
|
|
anotherGeojsonLayer.on("featureparse", function (e) {
|
|
var popupContent = "<p>I started out as a GeoJSON " + e.geometryType + ", but now I'm a Leaflet vector!</p>";
|
|
popupContent += "<p>This GeoJSON Point has been transformed into a custom Marker by passing a <code>pointToLayer</code> function in the <a href='http://leaflet.cloudmade.com/reference.html#geojson-options'>GeoJSON options</a> when instantiating the GeoJSON layer. View source for details.</p>";
|
|
if (e.properties && e.properties.popupContent) {
|
|
popupContent += e.properties.popupContent;
|
|
}
|
|
e.layer.bindPopup(popupContent);
|
|
});
|
|
|
|
lightRailGeojsonLayer.on("featureparse", function (e) {
|
|
var popupContent = "<p>I started out as a GeoJSON " + e.geometryType + ", but now I'm a Leaflet vector!</p>";
|
|
popupContent += "<p>This is the default look of a GeoJSON Point.</p>";
|
|
if (e.properties && e.properties.popupContent) {
|
|
popupContent += e.properties.popupContent;
|
|
}
|
|
e.layer.bindPopup(popupContent);
|
|
});
|
|
|
|
map.addLayer(geojsonLayer)
|
|
.addLayer(anotherGeojsonLayer)
|
|
.addLayer(lightRailGeojsonLayer);
|
|
|
|
geojsonLayer.addGeoJSON(freeBus);
|
|
geojsonLayer.addGeoJSON(bicycleRental);
|
|
geojsonLayer.addGeoJSON(campus);
|
|
|
|
anotherGeojsonLayer.addGeoJSON(coorsField);
|
|
|
|
lightRailGeojsonLayer.addGeoJSON(lightRailStop);
|
|
|
|
</script>
|
|
</body>
|
|
</html>
|