-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathscript.js
More file actions
137 lines (117 loc) · 4.14 KB
/
script.js
File metadata and controls
137 lines (117 loc) · 4.14 KB
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
// Edit the center point and zoom level
var map = L.map('map', {
center: [41.76, -72.69],
zoom: 12,
scrollWheelZoom: false
});
// set bounds for geocoder
var minLatLng = [41.711356, -72.802452];
var maxLatLng = [41.813259, -72.567709];
var bounds = L.latLngBounds(minLatLng, maxLatLng);
var choroplethLayer;
var choroplethOpacity = 0.7;
// create custom pane for town layer, set to display below overlay zIndex 400
map.createPane('towns');
map.getPane('towns').style.zIndex = 350;
new L.tileLayer('https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png', {
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> © <a href="http://cartodb.com/attributions">CartoDB</a>'
}).addTo(map);
var searchControl = L.esri.Geocoding.geosearch({
placeholder: "Search the Hartford area...",
searchBounds: bounds
}).addTo(map);
// Prepend attribution to "Powered by Esri"
map.attributionControl.setPrefix('View\
<a href="https://github.com/ontheline/otl-redlining" target="_blank">sources and code on GitHub</a>,\
created with ' + map.attributionControl.options.prefix);
var results = L.layerGroup().addTo(map);
searchControl.on('results', function (data) {
results.clearLayers();
for (var i = data.results.length - 1; i >= 0; i--) {
results.addLayer(L.marker(data.results[i].latlng));
}
});
L.control.scale().addTo(map);
// town outline layer, with custom pane set to display at lower z-index
$.getJSON("src/ct-towns-simple.geojson", function (data) {
L.geoJson(data, {
style: function (feature) {
return {
'color': 'gray',
'weight': 1,
fillOpacity: 0
}
},
onEachFeature: function( feature, layer) {
var popupText = "<b>" + feature.properties.town + "</b>";
layer.bindPopup(popupText);
},
pane: 'towns'
}).addTo(map);
});
var choroplethStyle = function(f) {
var grade2color = {
'A': 'green',
'B': '#3399ff', // light blue
'C': 'yellow',
'D': 'red',
}
return {
'color': 'black',
'weight': 1,
'fillColor': grade2color[ f.properties.grade ] || 'gray', // gray if no data
'fillOpacity': choroplethOpacity
}
}
// redlining polygons with fillColor
$.getJSON("polygons.geojson", function (data) {
choroplethLayer = L.geoJson(data, {
style: choroplethStyle,
onEachFeature: function( feature, layer) {
var popupText = "<b>Area " + feature.properties.name + " - " + feature.properties.town + "</b><br />"
+ "<a href='https://ontheline.github.io/otl-redlining/pdf/" + feature.properties.name + ".pdf' target='_blank'>Neighborhood report (PDF in new tab)</a>";
layer.bindPopup(popupText);
}
}).addTo(map);
map.fitBounds(choroplethLayer.getBounds())
});
// redlining points with colored numeric markers; see also style.css
$.getJSON("points.geojson", function (data){
L.geoJson(data, {
pointToLayer: function( feature, latlng) {
var colors = {
'A': 'green',
'B': 'blue',
'C': 'yellow',
'D': 'red',
}
var mIcon = L.ExtraMarkers.icon({
icon: 'fa-number',
number: feature.properties.name,
markerColor: colors[feature.properties.grade]
});
var marker = L.marker(latlng, {icon: mIcon});
var popupText = "<b>Area " + feature.properties.name + " - " + feature.properties.town + "</b><br />"
+ "<a href='https://ontheline.github.io/otl-redlining/pdf/" + feature.properties.name + ".pdf' target='_blank'>Neighborhood report (PDF in new tab)</a>";
marker.bindPopup(popupText);
return marker;
}
}).addTo(map);
});
// Add Opacity control
var opacity = L.control({position: 'bottomleft'});
opacity.onAdd = function (map) {
var div = L.DomUtil.create('div', 'control-custom range');
div.innerHTML = '<h4>Opacity</h4>';
div.innerHTML += '<input id="rangeSlider" type="range" min="0" max="100" value="70">';
// Make sure the map doesn't move with slider change
L.DomEvent.disableClickPropagation(div);
return div;
};
opacity.addTo(map);
$('#rangeSlider').on('input', function() {
choroplethOpacity = $(this).val() / 100;
if (choroplethLayer) {
choroplethLayer.setStyle(choroplethStyle);
}
})