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

Geojson #9

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
18 changes: 18 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
docs/*.json
node_modules
npm-debug.log
admin1CodesASCII.txt
Expand Down
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ packages

# Project
.github/
docs/
.prettierignore
.prettierrc
.release-it.json
Expand Down
56 changes: 56 additions & 0 deletions docs/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<!DOCTYPE html>
<html lang="en">
<head>
<base target="_top" />
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>cities.json - Cities of the World with a population > 1000</title>
<link
rel="stylesheet"
href="https://unpkg.com/[email protected]/dist/leaflet.css"
integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY="
crossorigin=""
/>
<script
src="https://unpkg.com/[email protected]/dist/leaflet.js"
integrity="sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo="
crossorigin=""
></script>

<style>
html,
body {
height: 100%;
margin: 0;
}
.leaflet-container {
height: 100%;
width: 100%;
max-width: 100%;
max-height: 100%;
}
.ribbon-link {
position: fixed;
right: 0;
top: 0;
z-index: 999;
}
</style>
</head>
<body>
<div id="map"></div>
<a class="ribbon-link" href="https://github.com/lutangar/cities.json"
><img
decoding="async"
width="149"
height="149"
src="https://github.blog/wp-content/uploads/2008/12/forkme_right_red_aa0000.png?resize=149%2C149"
class="attachment-full size-full"
alt="Fork me on GitHub"
loading="lazy"
data-recalc-dims="1"
/></a>
<script type="module" src="./index.js"></script>
<script></script>
</body>
</html>
29 changes: 29 additions & 0 deletions docs/index.js
Original file line number Diff line number Diff line change
@@ -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 = `<h2>${feature?.properties?.name}</h2>`;
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);
24 changes: 24 additions & 0 deletions geojson.js
Original file line number Diff line number Diff line change
@@ -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);
}
}
);
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down