108 lines
2.6 KiB
HTML
108 lines
2.6 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: white;
|
|
padding: 5px 10px;
|
|
box-shadow: 0 0 15px rgba(0,0,0,0.2);
|
|
border-radius: 5px;
|
|
font: 14px/1.5 Verdana, Tahoma, sans-serif;
|
|
text-align: right;
|
|
}
|
|
</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 © 2011 OpenStreetMap contributors, Imagery © 2011 CloudMade',
|
|
key: 'BC9A493B41014CAABB98F0471D759707',
|
|
styleId: 22677
|
|
}).addTo(map);
|
|
|
|
|
|
L.control.scale().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>' +
|
|
'<br>' + 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 style = L.Util.extend({}, defaultStyle, {
|
|
weight: 3,
|
|
color: '#555',
|
|
dashArray: ''
|
|
});
|
|
e.target.setStyle(style).bringToFront();
|
|
info.setFeature(e.target.feature);
|
|
}
|
|
|
|
function resetHighlight(e) {
|
|
e.target.setStyle(defaultStyle);
|
|
info.setFeature(null);
|
|
}
|
|
|
|
function onEachFeature(feature, layer) {
|
|
layer.feature = feature;
|
|
layer.on('mouseover', highlightFeature);
|
|
layer.on('mouseout', resetHighlight);
|
|
}
|
|
|
|
var geojson = L.geoJson(statesData, {
|
|
style: style,
|
|
onEachFeature: onEachFeature
|
|
}).addTo(map);
|
|
|
|
</script>
|
|
</body>
|
|
</html>
|