Add tjx stores
Requested-By: Käthe Swift
This commit is contained in:
parent
a038e5a0fa
commit
308ec72569
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -4,3 +4,4 @@ dist
|
|||
*.shp
|
||||
layers/dot-cams/*/data/states.js
|
||||
layers/survey-markers/states.js
|
||||
layers/tjx/data/chains.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;
|
||||
|
|
82
layers/tjx/get_data.py
Executable file
82
layers/tjx/get_data.py
Executable file
|
@ -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")
|
39
layers/tjx/index.js
Normal file
39
layers/tjx/index.js
Normal file
|
@ -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: `<a href="https://en.wikipedia.org/wiki/TJX_Companies">https://en.wikipedia.org/wiki/TJX_Companies</a>`,
|
||||
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;
|
13
layers/tjx/pin.svg
Normal file
13
layers/tjx/pin.svg
Normal file
|
@ -0,0 +1,13 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<svg
|
||||
viewBox="0 0 384 512"
|
||||
width="40px"
|
||||
height="30px"
|
||||
version="1.1"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:svg="http://www.w3.org/2000/svg">
|
||||
<!--! Font Awesome Pro 6.0.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2022 Fonticons, Inc. -->
|
||||
<path
|
||||
d="m 384,192 c 0,87.4 -117,243 -168.3,307.2 -12.3,15.3 -35.1,15.3 -47.4,0 C 116.1,435 0,279.4 0,192 0,85.96 85.96,0 192,0 245.96029,0 294.73775,22.275796 329.62577,58.136607 363.27205,92.721042 384,139.94065 384,192 Z"
|
||||
style="fill:#000;fill-opacity:1" />
|
||||
</svg>
|
After Width: | Height: | Size: 667 B |
Loading…
Reference in a new issue