Leaflet/debug/vector/geojson.html
2012-08-03 16:11:41 +03:00

112 lines
2.7 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<title>Leaflet debug page</title>
<link rel="stylesheet" href="../../dist/leaflet.css" />
<!--[if lte IE 8]><link rel="stylesheet" href="../../dist/leaflet.ie.css" /><![endif]-->
<link rel="stylesheet" href="../css/screen.css" />
<style>
.state-info {
background: rgba(255,255,255,0.8);
padding: 2px 10px 3px;
box-shadow: 0 0 15px rgba(0,0,0,0.2);
border-radius: 5px;
font: 16px/1.4 Arial, Helvetica, sans-serif;
}
</style>
<script src="../leaflet-include.js"></script>
</head>
<body>
<div id="map" style="height: 500px"></div>
<!--<input type="range" min="120" max="280" value="180" style="width: 800px" />-->
<script type="text/javascript" src="us-states.js"></script>
<script type="text/javascript">
var map = L.map('map').setView([37.8, -96.9], 4);
var cloudmade = L.tileLayer('http://{s}.tile.cloudmade.com/{key}/{styleId}/256/{z}/{x}/{y}.png', {
attribution: 'Map data &copy; 2011 OpenStreetMap contributors, Imagery &copy; 2011 CloudMade',
key: 'BC9A493B41014CAABB98F0471D759707',
styleId: 22677
}).addTo(map);
var info = L.Util.extend(L.control(), {
onAdd: function (map) {
var div = this._div = L.DomUtil.create('div', 'state-info');
info.setFeature(null);
return div;
},
setFeature: function (feature) {
this._div.innerHTML = (feature ?
'<b>' + feature.properties.name + '</b>' +
': ' + feature.properties.density + ' /mi<sup>2</sup>'
: 'Hover over a state');
}
});
info.addTo(map);
var defaultStyle = {
weight: 2,
opacity: 1,
color: 'white',
dashArray: '3 4',
fillOpacity: 0.8
};
function style(feature) {
var value = Math.min((Math.log(feature.properties.density) / Math.LN10) / 3, 1),
hue = Math.round(160 * (1 - value)),
style = {fillColor: 'hsl(' + hue + ',90%,42%)'};
return L.Util.extend({}, defaultStyle, style);
}
function highlightFeature(e) {
var layer = e.target;
layer.bringToFront().setStyle({
weight: 5,
color: '#666',
dashArray: ''
});
info.setFeature(e.target.feature);
}
function resetHighlight(e) {
e.target.setStyle(defaultStyle);
info.setFeature(null);
}
function zoomToFeature(e) {
map.fitBounds(e.target.getBounds());
}
function onEachFeature(feature, layer) {
layer.feature = feature;
layer.on('mouseover', highlightFeature);
layer.on('mouseout', resetHighlight);
layer.on('click', zoomToFeature);
}
var geojson = L.geoJson(statesData, {
style: style,
onEachFeature: onEachFeature
}).addTo(map);
</script>
</body>
</html>