diff --git a/layers/index.js b/layers/index.js index f7a0da9..9a7fe5f 100644 --- a/layers/index.js +++ b/layers/index.js @@ -8,6 +8,7 @@ import arenasLayer from './nhl-arenas/layer.js'; import bikepackingLayer from './bikepacking/layer.js'; import chains from './chains/index.js'; import census_bureau from './census-bureau/index.js'; +import states from './states/index.js'; const layerCategories = [ { // Base maps @@ -73,6 +74,7 @@ const layerCategories = [ }, chains, census_bureau, + states, ]; export default layerCategories; diff --git a/layers/states/get_data.sh b/layers/states/get_data.sh new file mode 100755 index 0000000..8612954 --- /dev/null +++ b/layers/states/get_data.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +for resolution in 20m 5m 500k; do + curl --silent --remote-name https://www2.census.gov/geo/tiger/GENZ2022/shp/cb_2022_us_state_${resolution}.zip + unzip cb_2022_us_state_${resolution}.zip + ogr2ogr -f GeoJSON us-states-${resolution}.geojson cb_2022_us_state_${resolution}.shp + sed -i '/^"crs":/d' us-states-${resolution}.geojson # TODO: handle this projection properly + rm cb_2022_us_state_${resolution}.* +done diff --git a/layers/states/index.js b/layers/states/index.js new file mode 100644 index 0000000..2941ff5 --- /dev/null +++ b/layers/states/index.js @@ -0,0 +1,90 @@ +import GeoJSON from 'ol/format/GeoJSON.js'; +import VectorLayer from 'ol/layer/Vector.js'; +import VectorSource from 'ol/source/Vector.js'; + +import highResStates from './us-states-500k.geojson?url'; +import medResStates from './us-states-5m.geojson?url'; +import lowResStates from './us-states-20m.geojson?url'; + +import { Fill, Stroke, Style, Text } from 'ol/style.js'; + +function style(feature){ + return new Style({ + text: new Text({ + text: feature.get('NAME'), + }), + fill: new Fill({ + color: 'rgba(255,255,255,0.4)', + }), + stroke: new Stroke({ + color: '#3399CC', + width: 1.25, + }), + }); +} + +const layers = { + name: "US States", + layers: [ + { + name: "All (high-res)", + layer: new VectorLayer({ + source: new VectorSource({ + url: highResStates, + format: new GeoJSON(), + }), + style: style, + }), + }, + { + name: "All (medium-res)", + layer: new VectorLayer({ + source: new VectorSource({ + url: medResStates, + format: new GeoJSON(), + }), + style: style, + }), + }, + { + name: "All (low-res)", + layer: new VectorLayer({ + source: new VectorSource({ + url: lowResStates, + format: new GeoJSON(), + }), + style: style, + }), + }, + ], +}; + +import visitedStatesLists from './visited.js'; + +for (let [visitor, visitedStates] of Object.entries(visitedStatesLists)) { + layers.layers.push({ + name: "Visited by " + visitor, + layer: new VectorLayer({ + source: new VectorSource({ + url: lowResStates, + format: new GeoJSON(), + }), + style: function(feature){ + return new Style({ + text: new Text({ + text: feature.get('NAME'), + }), + fill: new Fill({ + color: visitedStates.includes(feature.get('STUSPS')) ? 'rgba(128,255,128,0.4)' : 'rgba(255,127,127,0.4)', + }), + stroke: new Stroke({ + color: '#3399CC', + width: 1.25, + }), + }); + } + }), + }) +} + +export default layers; diff --git a/layers/states/visited.js b/layers/states/visited.js new file mode 100644 index 0000000..001428c --- /dev/null +++ b/layers/states/visited.js @@ -0,0 +1,122 @@ +const visitedStatesLists = { + Chandler: [ + 'AK', + 'AL', + 'AR', + 'AZ', + // 'CA', + 'CO', + // 'CT', + 'DE', + 'FL', + 'GA', + // 'HI', + 'IA', + // 'ID', + 'IL', + 'IN', + 'KS', + // 'KY', + 'LA', + 'MA', + 'MD', + 'ME', + 'MI', + 'MN', + 'MO', + 'MS', + 'MT', + 'NC', + 'ND', + 'NE', + 'NH', + // 'NJ', + 'NM', + // 'NV', + 'NY', + 'OH', + 'OK', + 'OR', + 'PA', + 'RI', + // 'SC', + 'SD', + 'TN', + 'TX', + // 'UT', + 'VA', + 'VT', + 'WA', + 'WI', + // 'WV', + 'WY', + ], + Käthe: [ + 'AL', + 'AR', + // 'AK', + 'AZ', + 'CA', + 'CO', + // 'CT', + 'DE', + 'FL', + 'GA', + 'HI', + 'IA', + 'ID', + 'IL', + 'IN', + 'KS', + // 'KY', + 'LA', + 'MA', + 'MD', + 'ME', + 'MI', + 'MN', + 'MO', + 'MS', + 'MT', + 'NC', + 'ND', + 'NE', + // 'NH', + // 'NJ', + // 'NM', + 'NV', + 'NY', + 'OH', + 'OK', + 'OR', + 'PA', + // 'RI', + // 'SC', + 'SD', + 'TN', + 'TX', + // 'UT', + 'VA', + // 'VT', + 'WA', + // 'WV', + 'WI', + 'WY', + ], + Eric: [ + 'AZ', + 'CO', + 'FL', + 'IA', + 'KS', + 'MN', + 'MO', + 'ND', + 'NE', + 'NM', + 'SD', + 'WI', + ], +} + +export default visitedStatesLists;