diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml new file mode 100644 index 0000000..37dfdae --- /dev/null +++ b/.github/workflows/docs.yml @@ -0,0 +1,18 @@ +name: Docs + +on: + push: + branches: ['master'] + pull_request: + branches: ['master'] + workflow_dispatch: +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: '16.x' + registry-url: 'https://registry.npmjs.org' + - run: npm install 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" },