-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Script to generate new spreadsheet layers (#531)
* initial script to generate new spreadsheet layers * introduce base code for spreadsheet based layers * new js based script for generating layers * refactor code * refactor actual script into a new file seperated the function in the existing file so as to make it compatible with both action and manual script * promisify the generate layer function * Add docs
- Loading branch information
1 parent
b8e0162
commit 7782b57
Showing
8 changed files
with
235 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[ | ||
{ | ||
"name": "testSpreadsheetLayer", | ||
"url": "https://docs.google.com/spreadsheets/d/1AR2KRuvxgruqLSCzJoIWxcyLDfPAE3tCifQthTHhpFo/" | ||
} | ||
] |