diff --git a/.gitignore b/.gitignore index 68107d3..a429cf2 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ dist *.shp layers/dot-cams/*/data/states.js layers/survey-markers/states.js +layers/tjx/data/chains.js diff --git a/layers/index.js b/layers/index.js index 025c744..411b74e 100644 --- a/layers/index.js +++ b/layers/index.js @@ -18,6 +18,7 @@ import state_land from './state-land/index.js'; import trips from './trips/index.js'; import dot_cams from './dot-cams/index.js'; import survey_markers from './survey-markers/index.js'; +import tjx from './tjx/index.js'; const layerCategories = [ { // Base maps @@ -99,6 +100,7 @@ const layerCategories = [ state_land, cellular, light_pollution, + tjx, ]; export default layerCategories; diff --git a/layers/tjx/get_data.py b/layers/tjx/get_data.py new file mode 100755 index 0000000..0f95abd --- /dev/null +++ b/layers/tjx/get_data.py @@ -0,0 +1,82 @@ +#!/usr/bin/python + +# Turns out alltheplaces has done all the hard work here; we can use their +# (CC0-licensed) data rather than trying to replicate the scraper ourselves. +# +# Unfortunately, many of the stores' individual location searches, including the +# parent TJX's list at https://www.tjx.com/stores, don't provide a list of +# stores, and only a search result. Some do, e.g. Sierra, with a chunk of +# javascript containing a list of JS objects, but this isn't consistent across +# stores, and I'm too lazy to reimplement something for every store. So, instead +# we take advantage of the hard work of those who have gone before us! + +import requests +import json + +data = requests.get('https://alltheplaces-data.openaddresses.io/runs/2024-04-20-13-31-46/output/tjx.geojson') + +chains = {} + +for store in data.json()['features']: + # store = { + # "type": "Feature", + # "id": "iaLJnlhrRR8daHXO0SGtTHQ2aYM=", + # "properties": { + # "ref": "93743", + # "@spider": "tjx", + # "shop": "department_store", + # "addr:full": "655 Sydney Ave", + # "addr:city": "Windsor", + # "addr:state": "ON", + # "addr:postcode": "N8X 5C4", + # "addr:country": "CA", + # "name": "Windsor", + # "phone": "+1 519-250-0494", + # "opening_hours": "Mo-Fr 09:30-21:00; Sa 09:00-21:00; Su 10:00-18:00", + # "brand": "Marshalls", + # "brand:wikidata": "Q15903261", + # "nsi_id": "marshalls-53f9e5" + # }, + # "geometry": { + # "type": "Point", + # "coordinates": [ + # -82.9981994628906, + # 42.2717170715332 + # ] + # } + # }, + if not store['properties']['brand'] in chains: + chains[store['properties']['brand']] = [] + chains[store['properties']['brand']].append({ + "type": "Feature", + "geometry": store['geometry'], + "properties": { + "name": store['properties']['name'], + "addr": store['properties']['addr:full'], + "city": store['properties']['addr:city'], + "state": store['properties']['addr:state'], + "postcode": store['properties']['addr:postcode'], + "country": store['properties']['addr:country'], + }, + }) + +safe_name = lambda s: ''.join([c.lower() for c in s if c.isalpha()]) + +for chain, features in chains.items(): + geojson = { + "type": "FeatureCollection", + "features": features, + } + + with open(f"data/{safe_name(chain)}.geojson", "w") as f: + f.write(json.dumps(geojson)) + + print(f"{len(features)} {chain} locations found") + +with open('data/chains.js', 'w') as f: + for chain in chains: + f.write(f"import {safe_name(chain)} from './{safe_name(chain)}.geojson?url';\n") + f.write('\nexport default {\n') + for chain in chains: + f.write(f" \"{chain}\": {safe_name(chain)},\n") + f.write("};\n") diff --git a/layers/tjx/index.js b/layers/tjx/index.js new file mode 100644 index 0000000..ee122ab --- /dev/null +++ b/layers/tjx/index.js @@ -0,0 +1,39 @@ +import VectorLayer from 'ol/layer/Vector'; +import {Vector as VectorSource} from 'ol/source.js'; +import GeoJSON from 'ol/format/GeoJSON.js'; + +import {Style} from 'ol/style.js'; +import Icon from 'ol/style/Icon.js'; + +import pin from './pin.svg?url'; +import data from './data/chains.js'; + +const chains = { + name: "TJX brands", + details: `https://en.wikipedia.org/wiki/TJX_Companies`, + layers: [], +}; + +for (let [chain, url] of Object.entries(data)) { + const vectorLayer = new VectorLayer({ + source: new VectorSource({ + url: url, + format: new GeoJSON, + }), + style: new Style({ + image: new Icon({ + anchor: [0.5, 1], + src: pin, + }), + }), + }); + + chains.layers.push({ + name: chain, + layer: vectorLayer, + }); +} + +chains.layers.sort((a, b) => a.name > b.name ? 1 : -1); // Names are always unique + +export default chains; diff --git a/layers/tjx/pin.svg b/layers/tjx/pin.svg new file mode 100644 index 0000000..36dca6a --- /dev/null +++ b/layers/tjx/pin.svg @@ -0,0 +1,13 @@ + + + + +