-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
137 lines (122 loc) · 5.59 KB
/
script.js
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// Template by http://github.com/jackdougherty/leaflet-map/
// See Leaflet tutorial links in README.md
// set up the map center and zoom level
var map = L.map('map', {
center: [41.6, -72.65], // [41.5, -72.7] for Connecticut; [41.76, -72.67] for Hartford county or city
zoom: 9, // zoom 9 for Connecticut; 10 for Hartford county, 12 for Hartford city
zoomControl: false // add later to reposition
});
// optional : customize link to view source code; add your own GitHub repository
map.attributionControl
.setPrefix('View <a href="https://github.com/jackdougherty/otl-metro-definitions">code on GitHub</a>, created with <a href="http://leafletjs.com" title="A JS library for interactive maps">Leaflet</a>');
// optional: add legend to toggle any baselayers and/or overlays
// global variable with (null, null) allows indiv layers to be added inside functions below
var controlLayers = L.control.layers( null, null, {
position: "bottomright", // suggested: bottomright for CT (in Long Island Sound); topleft for Hartford region
collapsed: false // false = open by default
}).addTo(map);
// optional: reposition zoom control other than default topleft
L.control.zoom({position: "topright"}).addTo(map);
/* BASELAYERS */
// use common baselayers below, delete, or add more with plain JavaScript from http://leaflet-extras.github.io/leaflet-providers/preview/
// .addTo(map); -- suffix displays baselayer by default
// controlLayers.addBaseLayer (variableName, 'label'); -- adds baselayer and label to legend; omit if only one baselayer with no toggle desired
var lightAll = new L.tileLayer('https://cartodb-basemaps-{s}.global.ssl.fastly.net/light_all/{z}/{x}/{y}.png', {
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, © <a href="http://cartodb.com/attributions">CartoDB</a>'
}).addTo(map); // adds layer by default
//controlLayers.addBaseLayer(lightAll, 'CartoDB LightAll');
/* POINT OVERLAYS */
// ways to load point map data from different sources: coordinates in the code, GeoJSON in local directory, remote GeoJSON and JSON
// load one point from coordinates in code, icon from local directory, no interactive legend button
// places a star on state capital of Hartford, CT
// * TO DO: test whether placement of this code affects its display order, on top of other icons?
var starIcon = L.icon({
iconUrl: 'src/star-18.png',
iconRetinaUrl: 'src/[email protected]',
iconSize: [18, 18]
});
L.marker([41.764, -72.682], {icon: starIcon}).addTo(map);
/* POLYGON OVERLAYS */
// load polygon data with clickable features from local directory
$.getJSON("src/CTtowns.geojson", function (data) { // insert pathname to your local directory file
var geoJsonLayer = L.geoJson(data, {
style: function (feature) {
return {
'color': 'black',
'weight': 1,
'fillColor': '#fff',
'fillOpacity': 0.2
}
},
onEachFeature: function( feature, layer) {
layer.bindPopup(feature.properties.Town) // change 'Town' to match your geojson property labels
}
}).addTo(map); // insert ".addTo(map)" to display layer by default
// controlLayers.addOverlay(geoJsonLayer, 'CT Towns'); // insert your 'Title' to add to legend
});
$.getJSON("src/1950-SMA.geojson", function (data) { // insert pathname to your local directory file
var geoJsonLayer = L.geoJson(data, {
style: function (feature) {
return {
'color': 'red',
'weight': 4
}
}
}).addTo(map); // insert ".addTo(map)" to display layer by default
controlLayers.addOverlay(geoJsonLayer, '1950 SMA'); // insert your 'Title' to add to legend
});
$.getJSON("src/1960-SMSA.geojson", function (data) { // insert pathname to your local directory file
var geoJsonLayer = L.geoJson(data, {
style: function (feature) {
return {
'color': 'blue',
'weight': 4
}
}
}); // insert ".addTo(map)" to display layer by default
controlLayers.addOverlay(geoJsonLayer, '1960 SMSA'); // insert your 'Title' to add to legend
});
$.getJSON("src/1963-SMSA.geojson", function (data) { // insert pathname to your local directory file
var geoJsonLayer = L.geoJson(data, {
style: function (feature) {
return {
'color': 'green',
'weight': 4
}
}
}); // insert ".addTo(map)" to display layer by default
controlLayers.addOverlay(geoJsonLayer, '1963 SMSA'); // insert your 'Title' to add to legend
});
$.getJSON("src/1973-SMSA.geojson", function (data) { // insert pathname to your local directory file
var geoJsonLayer = L.geoJson(data, {
style: function (feature) {
return {
'color': 'purple',
'weight': 4
}
}
}); // insert ".addTo(map)" to display layer by default
controlLayers.addOverlay(geoJsonLayer, '1973 SMSA'); // insert your 'Title' to add to legend
});
$.getJSON("src/1983-PMSA.geojson", function (data) { // insert pathname to your local directory file
var geoJsonLayer = L.geoJson(data, {
style: function (feature) {
return {
'color': 'green',
'weight': 4
}
}
}); // insert ".addTo(map)" to display layer by default
controlLayers.addOverlay(geoJsonLayer, '1983 PMSA'); // insert your 'Title' to add to legend
});
$.getJSON("src/1993-MSA.geojson", function (data) { // insert pathname to your local directory file
var geoJsonLayer = L.geoJson(data, {
style: function (feature) {
return {
'color': 'blue',
'weight': 4
}
}
}).addTo(map); // insert ".addTo(map)" to display layer by default
controlLayers.addOverlay(geoJsonLayer, '1993 MSA'); // insert your 'Title' to add to legend
});