-
Notifications
You must be signed in to change notification settings - Fork 2
/
censusexp.html
110 lines (108 loc) · 4.52 KB
/
censusexp.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<!DOCTYPE html>
<html>
<head>
<title>Census Experiment</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.5/leaflet.css" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script>
<!--<script type="text/javascript" charset="utf-8" src="./counties.json"> </script>-->
<!--[if lte IE 8]>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.5/leaflet.ie.css" />
<![endif]-->
<script src="http://cdn.leafletjs.com/leaflet-0.5/leaflet.js"></script>
<script type="text/javascript">
var map;
var serviceArea;
var serviceAreaCenter = [42.369373, -72.639241];
var layerStack = []; // holds initial collection of layers
var layerControl = new L.Control.Layers();
// Data to put on map initially:
var geoJSONStack = [
{
geoJSON: './CommunityActionServiceArea.json',
properties: { style: { color: '#4E6C9B', fill: false, weight: 7, opacity: 0.75 } },
controlName: '<span style="color: #4E6C9B;">Service Area ━━━━</span>'
},
{
geoJSON: './USStates.json',
properties: { style: { color: 'purple', fill: false, weight: 3, dashArray: '5,5' } },
controlName: '<span style="color: purple;">States ╺╸ ╺╸╺╸</span>'
},
{
geoJSON: './MassachusettsCounties.json',
properties: { style: { color: 'black', fill: false, weight: 3 } },
controlName: '<span style="color: black">Counties ━━━━</span>'
},
{
geoJSON: './CommunityActionTracts.json',
properties: { style: { color: 'black', fill: false, weight: 1 } },
controlName: 'Census Tracts ────'
}
]
function mapGeoJSONStack(geoJSON)
{
if (geoJSON) // called by $.getJSON, with reference to imported data
{
var geoJSONData = geoJSONStack.pop();
var layer = new L.geoJson(geoJSON, geoJSONData.properties);
layer.addTo(map);
layerControl.addOverlay(layer, geoJSONData.controlName);
layerStack.push(layer) // store reference
}
if (geoJSONStack.length)
$.getJSON(geoJSONStack[geoJSONStack.length-1].geoJSON, mapGeoJSONStack);
else
layerControl.addTo(map);
}
var fuelGaugeIcon = L.icon(
{
iconUrl: 'http://www3.amherst.edu/~aanderson/hack/fuel_gauge_www.fotosearch.com.jpg',
iconSize: [46, 32],
/*iconRetinaUrl: 'my-icon@2x.png',
iconAnchor: [22, 94],
popupAnchor: [-3, -76],
shadowUrl: 'my-icon-shadow.png',
shadowRetinaUrl: 'my-icon-shadow@2x.png',
shadowSize: [68, 95],
shadowAnchor: [22, 94]*/
});
</script>
</head>
<body>
<div id="map" style="width: 800px; height: 600px"></div>
<script>
//Get the json
//var communityactionarea = $.ajax("CommunityActionServiceArea.json").done( function (data){return data}) // I don't like this.
// Set the default screen.
map = L.map('map').setView(serviceAreaCenter, 9);
// Info: http://developers.cloudmade.com/projects/tiles/documents
// http://leafletjs.com/reference.html#tilelayer
// Tile styles can be found in lower right corner of this gallery: http://maps.cloudmade.com/editor
L.tileLayer('http://{s}.tile.cloudmade.com/{key}/{styleId}/256/{z}/{x}/{y}.png', {
attribution: 'Map data © 2011 OpenStreetMap contributors, Imagery © 2012 CloudMade',
key: 'BC9A493B41014CAABB98F0471D759707',
styleId: 22677
}).addTo(map);
// Our data, an array from `ogr2ogr` output
// L.geoJson(counties, {
// style: function (feature) {
// //Display color, our data does not have specific colors in the shapefile prodided.
// return {color: "blue"};
// },
// onEachFeature: function (feature, layer) {
// // description but not determinate by the item. Can call FIPS-id to describe.
// layer.bindPopup("NOPE");
// }
// }).addTo(map);
//Second dataset.
mapGeoJSONStack(); // first call no arguments
L.control.scale().addTo(map);
// Bind to zoom/pan information
// For development ease, remove on deploy.
map.on("zoomend", function(){console.log(map.getZoom())});
map.on("moveend", function(){console.log(map.getCenter().toString())});
L.marker(serviceAreaCenter, { title: 'Community ACTION Service Area', icon: fuelGaugeIcon } ).addTo(map)
</script>
</body>
</html>