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

Script to generate new spreadsheet layers #531

Merged
merged 7 commits into from
Aug 3, 2021
Merged
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
31 changes: 31 additions & 0 deletions scripts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Generate New Spreadsheet Layer

This directory contains scripts and logic for manual as well as automated generation of new spreadsheet based layers.

## Steps to manually generate layer

1. Create `input.json`
```sh
cp sample.input.json
```

2. Replace values in `input.json` with the data for new spreadsheet layer
3. Execute `manualGenLayer.js`
```sh
node manualGenLayer.js
```
4. Check if json files are modified inside `src/`
5. Build the entire package
```sh
grunt build
```
6. Modify example files and check if you can use the newly generated layer
```sh
npm start
```
7. Commit Files and Create Pull Request


## Automatically Generate Layer

// To be added in follow up PR
62 changes: 62 additions & 0 deletions scripts/genSpreadsheetLayer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
const { writeFile, readFile } = require("fs").promises;
const path = require("path");

async function generateSpreadsheetLayer(layerData, confirm) {
let newSpreadsheetLayers, newLayerInfo;
try {
const data = await readFile(
path.resolve(__dirname, "../src/spreadsheetLayers/layers.json"),
"utf8"
);
let spreadsheetLayers = JSON.parse(data);
spreadsheetLayers.push({
name: layerData.name,
url: layerData.url,
});
newSpreadsheetLayers = spreadsheetLayers;
if (confirm) {
await writeFile(
path.resolve(__dirname, "../src/spreadsheetLayers/layers.json"),
JSON.stringify(spreadsheetLayers, null, 2),
"utf8"
);
}
console.log("Successful");
} catch (error) {
console.error(e);
}

try {
const data = await readFile(
path.resolve(__dirname, "../src/info.json"),
"utf8"
);
let layerInfo = JSON.parse(data);
layerInfo[layerData.name] = {
name: layerData.name,
url: "",
data: {
type: "",
disclaimer: "",
},
description: "",
layer_desc: layerData.description,
icon: "#cc12cc",
};
newLayerInfo = layerInfo;
if (confirm) {
await writeFile(
path.resolve(__dirname, "../src/info.json"),
JSON.stringify(layerInfo, null, 2),
"utf8"
);
}
console.log("Successful");
} catch (error) {
console.error(e);
}
return { newSpreadsheetLayers, newLayerInfo };
}

exports.generateSpreadsheetLayer = (...data) =>
generateSpreadsheetLayer(...data);
8 changes: 8 additions & 0 deletions scripts/manualGenLayer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const path = require("path");
const fs = require("fs");
const { generateSpreadsheetLayer } = require("./genSpreadsheetLayer");

(async () => {
let layerData = await JSON.parse(fs.readFileSync("input.json", "utf8"));
await generateSpreadsheetLayer(layerData, true);
})();
5 changes: 5 additions & 0 deletions scripts/sample.input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "testSpreadsheetLayer",
"description": "Spreadsheet data",
"url": "https://docs.google.com/spreadsheets/d/1AR2KRuvxgruqLSCzJoIWxcyLDfPAE3tCifQthTHhpFo/"
}
131 changes: 105 additions & 26 deletions src/info.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"fractracker": {
"name": "FracTracker",
"url": "https://www.fractracker.org/",
"api_url": "https://spreadsheets.google.com/feeds/list/19j4AQmjWuELuzn1GIn0TFRcK42HjdHF_fsIa8jtM1yw/o4rmdye/public/values?alt=json" ,
"api_url": "https://spreadsheets.google.com/feeds/list/19j4AQmjWuELuzn1GIn0TFRcK42HjdHF_fsIa8jtM1yw/o4rmdye/public/values?alt=json",
"data": {
"type": "",
"disclaimer": "Data from agency data sets to crowd-sourced data"
Expand Down Expand Up @@ -54,7 +54,11 @@
},
"indigenousLands": {
"name": "Indigenous Lands",
"layers": ["Territories", "Languages", "Treaties"],
"layers": [
"Territories",
"Languages",
"Treaties"
],
"url": "https://native-land.ca/",
"data": {
"type": "Historical data",
Expand All @@ -70,7 +74,17 @@
},
"justiceMap": {
"name": "Justice Map",
"layers": ["income", "americanIndian", "asian", "black", "multi", "hispanic", "nonWhite", "white", "plurality"],
"layers": [
"income",
"americanIndian",
"asian",
"black",
"multi",
"hispanic",
"nonWhite",
"white",
"plurality"
],
"url": "http://www.justicemap.org/index.php?giAdvanced=0#instruction_div",
"data": {
"type": "",
Expand All @@ -81,9 +95,15 @@
"icon": "#f3a482",
"extents": {
"bounds": [
[16.97274101999902, -172.880859375],
[71.27259471233448, -38.05664062500001]
],
[
16.97274101999902,
-172.880859375
],
[
71.27259471233448,
-38.05664062500001
]
],
"minZoom": 5,
"maxZoom": 15
}
Expand Down Expand Up @@ -145,7 +165,12 @@
},
"openInfraMap": {
"name": "Open Infra Map",
"layers": ["Power", "Petroleum", "Telecom", "Water"],
"layers": [
"Power",
"Petroleum",
"Telecom",
"Water"
],
"url": "https://openinframap.org/about.html",
"contribute_url": "https://openinframap.org/about.html",
"data": {
Expand All @@ -170,7 +195,20 @@
},
"openWeatherMap": {
"name": "Open Weather Map",
"layers": ["clouds", "cloudsClassic", "precipitation", "precipitationClassic", "rain", "rainClassic", "snow", "pressure", "pressureContour", "temperature", "wind", "city"],
"layers": [
"clouds",
"cloudsClassic",
"precipitation",
"precipitationClassic",
"rain",
"rainClassic",
"snow",
"pressure",
"pressureContour",
"temperature",
"wind",
"city"
],
"url": "https://openweathermap.org/guide",
"data": {
"type": "RT",
Expand Down Expand Up @@ -209,9 +247,15 @@
"icon": "#b52822",
"extents": {
"bounds": [
[16.97274101999902, -172.880859375],
[71.27259471233448, -38.05664062500001]
],
[
16.97274101999902,
-172.880859375
],
[
71.27259471233448,
-38.05664062500001
]
],
"minZoom": 5,
"maxZoom": 15
}
Expand All @@ -232,9 +276,9 @@
"purpleLayer": {},
"purpleairmarker": {
"extents": {
"minZoom": 8,
"maxZoom": 15
}
"minZoom": 8,
"maxZoom": 15
}
}
}
},
Expand Down Expand Up @@ -267,9 +311,15 @@
"icon": "#6ccc00",
"extents": {
"bounds": [
[60.54377524118842, -21.708984375000004],
[13.66733825965496, -148.27148437500003]
],
[
60.54377524118842,
-21.708984375000004
],
[
13.66733825965496,
-148.27148437500003
]
],
"minZoom": 5,
"maxZoom": 15
}
Expand All @@ -287,9 +337,15 @@
"icon": "#4f4fff",
"extents": {
"bounds": [
[42.2102, -72.0204],
[41.2272, -70.9618]
],
[
42.2102,
-72.0204
],
[
41.2272,
-70.9618
]
],
"minZoom": 6,
"maxZoom": 18
}
Expand All @@ -307,9 +363,15 @@
"icon": "#739ccf",
"extents": {
"bounds": [
[43.689721907017194, -93.12835693359376],
[45.60250901510299, -89.54956054687501]
],
[
43.689721907017194,
-93.12835693359376
],
[
45.60250901510299,
-89.54956054687501
]
],
"minZoom": 10,
"maxZoom": 15
}
Expand All @@ -326,11 +388,28 @@
"icon": "#096",
"extents": {
"bounds": [
[-44.087585028245165, -148.88671875000003],
[76.63922560965888, 140.62500000000003]
],
[
-44.087585028245165,
-148.88671875000003
],
[
76.63922560965888,
140.62500000000003
]
],
"minZoom": 3,
"maxZoom": 18
}
},
"testSpreadsheetLayer": {
"name": "testSpreadsheetLayer",
"url": "",
"data": {
"type": "",
"disclaimer": ""
},
"description": "",
"layer_desc": "Spreadsheet data",
"icon": "#cc12cc"
}
}
1 change: 1 addition & 0 deletions src/leafletEnvironmentalLayers.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ require('./PLpeopleLayer.js');
require('./layercode.js');
require('./eonetFiresLayer');
require('./AllLayers.js');
require('./spreadsheetLayers')
17 changes: 17 additions & 0 deletions src/spreadsheetLayers/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const layers = require("./layers.json");

for (const layer of layers) {
//Evaluate based on dynamic data
let newLayer = function (options) {
return new L.SpreadsheetLayer({
url: layer.url,
lat: "Latitude",
lon: "Longitude",
generatePopup: function () {},
imageOptions: {
icon: L.icon.mapKnitterIcon(),
},
});
};
eval("L.layerGroup." + layer.name + "=newLayer");
}
6 changes: 6 additions & 0 deletions src/spreadsheetLayers/layers.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"name": "testSpreadsheetLayer",
"url": "https://docs.google.com/spreadsheets/d/1AR2KRuvxgruqLSCzJoIWxcyLDfPAE3tCifQthTHhpFo/"
}
]