From cdc5b366e7dbb4aed3b073847de563c888691d79 Mon Sep 17 00:00:00 2001 From: lutangar Date: Wed, 29 Nov 2023 16:42:08 +0100 Subject: [PATCH 1/3] Displaying on a map --- .gitignore | 1 + .npmignore | 1 + docs/index.html | 56 +++++++++++++++++++++++++++++++++++++++++++++++++ docs/index.js | 29 +++++++++++++++++++++++++ geojson.js | 24 +++++++++++++++++++++ package.json | 1 + 6 files changed, 112 insertions(+) create mode 100644 docs/index.html create mode 100644 docs/index.js create mode 100644 geojson.js diff --git a/.gitignore b/.gitignore index 5834b88..cde79e5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +docs/*.json node_modules npm-debug.log admin1CodesASCII.txt diff --git a/.npmignore b/.npmignore index 8b24c44..a05090e 100644 --- a/.npmignore +++ b/.npmignore @@ -42,6 +42,7 @@ packages # Project .github/ +docs/ .prettierignore .prettierrc .release-it.json diff --git a/docs/index.html b/docs/index.html new file mode 100644 index 0000000..e90fba4 --- /dev/null +++ b/docs/index.html @@ -0,0 +1,56 @@ + + + + + + + cities.json - Cities of the World with a population > 1000 + + + + + + +
+ Fork me on GitHub + + + + diff --git a/docs/index.js b/docs/index.js new file mode 100644 index 0000000..bf98b95 --- /dev/null +++ b/docs/index.js @@ -0,0 +1,29 @@ +import cities from './cities.geo.json' assert { type: 'json' }; + +const map = L.map('map').setView([45.74846, 4.84671], 15); + +L.tileLayer( + 'https://{s}.basemaps.cartocdn.com/rastertiles/light_nolabels/{z}/{x}/{y}.png', + { + maxZoom: 18, + } +).addTo(map); + +function onEachFeature(feature, layer) { + const popupContent = `

${feature?.properties?.name}

`; + layer.bindPopup(popupContent); +} + +L.geoJSON([cities], { + onEachFeature, + pointToLayer(feature, latlng) { + return L.circleMarker(latlng, { + radius: 5, + fillColor: '#ff7800', + color: '#000', + weight: 1, + opacity: 1, + fillOpacity: 0.8, + }); + }, +}).addTo(map); diff --git a/geojson.js b/geojson.js new file mode 100644 index 0000000..99d67f0 --- /dev/null +++ b/geojson.js @@ -0,0 +1,24 @@ +const cities = require('./cities.json'); +const jsonfile = require('jsonfile'); + +const mapCityToPointFeature = ({ lat, lng, ...properties }) => ({ + type: 'Feature', + properties, + geometry: { + type: 'Point', + coordinates: [parseFloat(lng), parseFloat(lat)], + }, +}); +jsonfile.writeFile( + './docs/cities.geo.json', + { + type: 'FeatureCollection', + features: cities.map(mapCityToPointFeature), + }, + { spaces: 2 }, + (e) => { + if (e) { + console.error(e); + } + } +); diff --git a/package.json b/package.json index 4eb287c..c6b6ade 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "convert": "node convert", "download": "node download", "build": "npm run download && npm run convert", + "geojson": "node geojson", "prettier": "prettier -w -u .", "release": "release-it" }, From c3b4252658ed0bd4ea6147813bd1b80489e72a84 Mon Sep 17 00:00:00 2001 From: lutangar Date: Wed, 29 Nov 2023 16:49:57 +0100 Subject: [PATCH 2/3] Add Github action to publish/update docs --- .github/workflows/docs.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 .github/workflows/docs.yml diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml new file mode 100644 index 0000000..9d50b3c --- /dev/null +++ b/.github/workflows/docs.yml @@ -0,0 +1,15 @@ +name: Docs + +on: + push: + branches: ['master'] + pull_request: + branches: ['master'] + workflow_dispatch: +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Run a one-line script + run: npm run geojson From 885fa9be66b5115080515489af85ee39146f95be Mon Sep 17 00:00:00 2001 From: lutangar Date: Wed, 29 Nov 2023 16:52:56 +0100 Subject: [PATCH 3/3] Update docs script --- .github/workflows/docs.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 9d50b3c..37dfdae 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -11,5 +11,8 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - name: Run a one-line script - run: npm run geojson + - uses: actions/setup-node@v3 + with: + node-version: '16.x' + registry-url: 'https://registry.npmjs.org' + - run: npm install