Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add senate and house districts #4

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions public/build/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/build/bundle.js.map

Large diffs are not rendered by default.

141 changes: 141 additions & 0 deletions public/data/house22.geojson

Large diffs are not rendered by default.

74 changes: 74 additions & 0 deletions public/data/senate22.geojson

Large diffs are not rendered by default.

94 changes: 76 additions & 18 deletions src/Layer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
export let map;
export let layer;
export let currentPercent = layer.initialValue;
export let visible = true;
export let visible = layer.visible;
export let keyOpacity = 0.6;
export let popup;
export let hoverLayer = false;
Expand All @@ -20,6 +20,12 @@
"visibility",
visible ? "visible" : "none"
);
layer.alsoType &&
map.setLayoutProperty(
layer.layer + "-line",
"visibility",
visible ? "visible" : "none"
);
}
}

Expand Down Expand Up @@ -62,6 +68,31 @@
"airport-label"
);
}
if (layer.alsoType === "line") {
map.addLayer(
{
id: layer.layer + "-line",
type: "line",
source: layer.layer,
paint: {
"line-color": layer.alsoColor,
"line-width": 1,
},
},
"waterway-label"
);
}
map.setLayoutProperty(
layer.layer,
"visibility",
visible ? "visible" : "none"
);
layer.alsoType &&
map.setLayoutProperty(
layer.layer + "-line",
"visibility",
visible ? "visible" : "none"
);
!layer.static &&
map.setFilter(layer.layer, [">=", layer.propName, currentPercent]);
};
Expand All @@ -83,15 +114,41 @@
onMount(() => {
getData(map);
const mapContainer = map.getCanvas();
map.on("mouseenter", "air-permits", function (e) {
mapContainer.style.cursor = "pointer";
const name = e.features[0].properties["Master AI Name"];
popup.setLngLat(e.lngLat).setHTML(name).addTo(map);
});
map.on("mouseleave", "air-permits", function () {
mapContainer.style.cursor = "";
popup.remove();
});
// map.on("mouseenter", "air-permits", function (e) {
// mapContainer.style.cursor = "pointer";
// const name = e.features[0].properties["Master AI Name"];
// popup.setLngLat(e.lngLat).setHTML(name).addTo(map);
// });
map.on(
"mousemove",
["house-districts", "senate-districts", "air-permits"],
function (e) {
mapContainer.style.cursor = "pointer";
//if source of any feature is air-permits, show only that name
if (e.features.some((feature) => feature.source === "air-permits")) {
const name =
"MPCA air permit for -<br><b>" +
e.features[0].properties["Master AI Name"] +
"</b>";
popup.setLngLat(e.lngLat).setHTML(name).addTo(map);
return;
}
let name = "";
e.features.map((feature) => {
name += feature.source === "house-districts" ? "House " : "Senate ";
name += "<b>" + feature.properties["DISTRICT"] + "</b><br>";
});
popup.setLngLat(e.lngLat).setHTML(name).addTo(map);
}
);
map.on(
"mouseleave",
["house-districts", "senate-districts", "air-permits"],
function () {
mapContainer.style.cursor = "";
popup.remove();
}
);

map.on("mouseenter", layer.layer, () => {
hoverLayer = true;
Expand All @@ -109,16 +166,17 @@
: null}"
on:mouseenter={() => flashLayer(0.8)}
on:mouseleave={() => flashLayer(0.6)}
on:focus={() => flashLayer()}
>
<div class="keyWrap">
<div
class="key"
style="opacity: {keyOpacity}; background-color: {layer.color}; {layer.type ===
'point'
? 'border-radius: 10px;'
: 'border-radius: 2px;'}"
/>
{#if !layer.alsoType}
<div
class="key"
style="opacity: {keyOpacity}; background-color: {layer.color}; {layer.type ===
'point'
? 'border-radius: 10px;'
: 'border-radius: 2px;'}"
/>
{/if}
<input type="checkbox" bind:checked={visible} />
</div>
{#if !layer.static}
Expand Down
33 changes: 33 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const layers = [
url: "data/poverty_lt_200perc.geojson",
color: "#729b6f",
initialValue: 35,
visible: true,
},
{
name: "Non-white",
Expand All @@ -18,6 +19,7 @@ const layers = [
url: "data/nonwhite.geojson",
color: "#8d5a99",
initialValue: 40,
visible: true,
},
{
name: "Speak English 'less than very well'",
Expand All @@ -27,6 +29,7 @@ const layers = [
url: "data/engl_ltvw.geojson",
color: "#e77148",
initialValue: 40,
visible: true,
},
];
const staticLayers = [
Expand All @@ -39,6 +42,7 @@ const staticLayers = [
color: "grey",
initialValue: null,
static: true,
visible: true,
},
{
name: "Major air permit locations (MPCA)",
Expand All @@ -50,6 +54,35 @@ const staticLayers = [
initialValue: null,
static: true,
link: "https://www.pca.state.mn.us/business-with-us/part-70-manufacturing-general-permit",
visible: true,
},
{
name: "MN Senate Districts",
layer: "senate-districts",
propName: null,
type: "polygon",
alsoType: "line",
url: "data/senate22.geojson",
color: "rgba(0,0,0,0)",
alsoColor: "#444444",
initialValue: null,
static: true,
link: null,
visible: false,
},
{
name: "MN House Districts",
layer: "house-districts",
propName: null,
type: "polygon",
alsoType: "line",
url: "data/house22.geojson",
color: "rgba(0,0,0,0)",
alsoColor: "#444444",
initialValue: null,
static: true,
link: null,
visible: false,
},
];

Expand Down