Public
Edited
Apr 19, 2023
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
viewof canadaMap = {
let height = 450;
let container = DOM.element('div', {style: `width:${width}px;height:${height}px;border-radius:4px;`});
yield container;
let map = L.map(container, { maxZoom: 10, minZoom: 3 });
let baseLayer = L.tileLayer(cartoDark,{
attribution: cartoAttr,
opacity: 1
})
.addTo(map);

let popProvince = L.geoJson(json, {
style: stylePop,
onEachFeature: areaClick
})
.bindTooltip(function(d) {
return d.feature.properties.prov_name_en + '<br> Pop change (%): '
+ d.feature.properties.pop_perc + '<br> Pop (thousands): ' + d.feature.properties.pop_thou
})
.addTo(map);

let showSelProv = function(d) {
if (mapSel === d) {
return 1;
}
return 0.5;
}

let selProv = L.geoJson(json, {
style: function(feature) {
return {
fillOpacity: showSelProv(feature.properties.prov_name_en[0]),
color: 0,
}
}
}).addTo(map)

let birthProvince = L.geoJson(json, {
style: birthCols,
onEachFeature: areaClick
})
.bindTooltip(function(d) {return contTooltip(d.feature)})
if (mapShowType == "Place of birth") {
birthProvince.addTo(map);
} else {
popProvince.addTo(map);
}

var legend = L.control({position: 'bottomright'});
legend.onAdd = function(map) {
var div = L.DomUtil.create('div', 'info legend'),
grades = legendGrades(),
labels = ['-2 - -1', '-1 - 0', '1 - 0', '0 - 1', '1 - 2', '2 - 3', '3 - 4', '4 - 5', '5 - 6', '6 - 7', '7 - 8', '8 - 9', '9 - 10', '10+'];

for (var i = 0; i < grades.length; i++) {
if (mapShowType == "Place of birth") {
div.innerHTML +=
'<i style = "background-color:' + getBirthCol(grades[i]) + '"></i> ' +
grades[i] + (grades[i + 1] ? '&ndash;' + grades[i + 1] + '<br>' : '+');
} else {
div.innerHTML +=
'<i style = "background-color:' + getPopChangeCol(grades[i]) + '"></i> ' +
grades[i] + (grades[i + 1] ? '&ndash;' + grades[i + 1] + '<br>' : '+');
}
}
return div;
};
legend.addTo(map);

map.on("mousedown", () => (mutable mapSel = null));

map.fitBounds(birthProvince.getBounds());
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function stylePop(feature) {
return {
fillColor: getPopChangeCol(feature.properties.pop_perc),
weight: 2,
opacity: .5,
color: 'white',
fillOpacity: 0.5,
// fillOpacity: getProvSel(feature.properties.prov_name_en),
onEachFeature: areaClick
};
}
Insert cell
function highlightProvince(e) {
var layer = e.target;
layer.setStyle({
weight: 5,
color: '#f03a3a'
})
layer.bringToFront();
}
Insert cell
function resetHightlight(e) {
json.resetStyle(e.target);
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function areaClick(feature, layer) {
layer.on({
click:whenClicked
});

// if (mapSel.contains(feature.properties['GEOGRAPHY NAME'])) {
// if ({field: 'GEOGRAPHY NAME', oneOf: mapSels}) {
// layer.on({
// click: highlightProvince,
// })
// }
}
Insert cell
whenClicked = (event) => {
mutable mapSel = [event.target.feature.properties.prov_name_en[0]]
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more