Skip to content

Instantly share code, notes, and snippets.

@jleedev
Last active June 15, 2022 16:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jleedev/f8009c33d0af025eca35347deeaed5ee to your computer and use it in GitHub Desktop.
Save jleedev/f8009c33d0af025eca35347deeaed5ee to your computer and use it in GitHub Desktop.
natural earth
set -eux
docker build . -t us-central1-docker.pkg.dev/asdf-f6040/my-docker-repo/natural_earth
docker push us-central1-docker.pkg.dev/asdf-f6040/my-docker-repo/natural_earth
CLOUDSDK_CORE_PROJECT=asdf-f6040 gcloud run deploy natural-earth --region=us-central1 --image=us-central1-docker.pkg.dev/asdf-f6040/my-docker-repo/natural_earth --quiet --allow-unauthenticated
FROM debian:bullseye AS builder
RUN apt-get update && apt-get -y install gdal-bin build-essential git curl libsqlite3-dev zlib1g-dev
WORKDIR /build
RUN git clone https://github.com/mapbox/tippecanoe
RUN cd ./tippecanoe && make && make install
RUN curl -OL https://www.naturalearthdata.com/http//www.naturalearthdata.com/download/10m/cultural/ne_10m_admin_0_countries_lakes.zip
RUN ogr2ogr ne_10m_admin_0_countries_lakes.geojson /vsizip/ne_10m_admin_0_countries_lakes.zip
RUN ogr2ogr countries_points.geojson -dialect sqlite -sql 'select ST_PointOnSurface(geometry),featurecla,scalerank,LABELRANK,SOVEREIGNT,SOV_A3,ADM0_DIF,LEVEL,TYPE,TLC,ADMIN,ADM0_A3,GEOU_DIF,GEOUNIT,GU_A3,SU_DIF,SUBUNIT,SU_A3,BRK_DIFF,NAME,NAME_LONG,BRK_A3,BRK_NAME,BRK_GROUP,ABBREV,POSTAL,FORMAL_EN,FORMAL_FR,NAME_CIAWF,NOTE_ADM0,NOTE_BRK,NAME_SORT,NAME_ALT,MAPCOLOR7,MAPCOLOR8,MAPCOLOR9,MAPCOLOR13,POP_EST,POP_RANK,POP_YEAR,GDP_MD,GDP_YEAR,ECONOMY,INCOME_GRP,FIPS_10,ISO_A2,ISO_A2_EH,ISO_A3,IS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S_GR,FCLASS_IT,FCLASS_NL,FCLASS_SE,FCLASS_BD,FCLASS_UA from ne_10m_admin_0_countries_lakes' ne_10m_admin_0_countries_lakes.geojson
RUN tippecanoe -z6 -o countries.mbtiles ne_10m_admin_0_countries_lakes.geojson
RUN tippecanoe -r1 -z6 -o countries_points.mbtiles countries_points.geojson
RUN tile-join -o output.mbtiles countries.mbtiles countries_points.mbtiles
FROM consbio/mbtileserver
COPY --from=builder /build/output.mbtiles /tilesets/
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />
<script src='https://unpkg.com/maplibre-gl@2.1.9/dist/maplibre-gl.js'></script>
<link href='https://unpkg.com/maplibre-gl@2.1.9/dist/maplibre-gl.css' rel='stylesheet' />
<style>
#map {position: absolute; top: 0; right: 0; bottom: 0; left: 0;}
</style>
</head>
<body>
<div id="map"></div>
<script>
var map = new maplibregl.Map({
container: 'map',
style: '/style.json',
center: [0, 0],
zoom: 1
});
</script>
</body>
</html>
{
"version": 8,
"glyphs": "https://fonts.openmaptiles.org/{fontstack}/{range}.pbf",
"sources": {
"natural-earth": {
"type": "vector",
"url": "https://natural-earth-scratch-x5m3uj6fcq-uc.a.run.app/services/output"
}
},
"layers": [
{
"id": "background",
"type": "background",
"paint": {
"background-color": "#D8F2FF"
}
},
{
"id": "coastline",
"type": "line",
"source": "natural-earth",
"source-layer": "ne_10m_admin_0_countries_lakes",
"paint": {
"line-blur": 0.5,
"line-color": "#198EC8",
"line-width": [
"interpolate",
[
"exponential",
2
],
[
"zoom"
],
0,
2,
6,
6,
14,
9,
22,
18
]
},
"layout": {
"line-cap": "round",
"line-join": "round"
}
},
{
"id": "countries",
"type": "fill",
"source": "natural-earth",
"source-layer": "ne_10m_admin_0_countries_lakes",
"paint": {
"fill-color": [
"to-color",
[
"at",
[
"get",
"MAPCOLOR9"
],
[
"literal",
[
"#66C5CC",
"#F6CF71",
"#F89C74",
"#DCB0F2",
"#87C55F",
"#9EB9F3",
"#FE88B1",
"#C9DB74",
"#8BE0A4",
"#B497E7",
"#D3B484",
"#B3B3B3"
]
]
]
]
}
},
{
"id": "countries-boundary",
"type": "line",
"source": "natural-earth",
"source-layer": "ne_10m_admin_0_countries_lakes",
"paint": {
"line-color": "rgba(255, 255, 255, 1)",
"line-width": [
"interpolate",
[
"exponential",
2
],
[
"zoom"
],
1,
1,
6,
2,
14,
6,
22,
12
],
"line-opacity": [
"interpolate",
[
"exponential",
2
],
[
"zoom"
],
3,
0.5,
6,
1
]
},
"layout": {
"line-cap": "round",
"line-join": "round"
}
},
{
"id": "countries-label",
"type": "symbol",
"source": "natural-earth",
"source-layer": "countries_points",
"paint": {
"text-color": "rgba(8, 37, 77, 1)",
"text-halo-blur": {
"stops": [
[
2,
0.2
],
[
6,
0
]
]
},
"text-halo-color": "rgba(255, 255, 255, 1)",
"text-halo-width": {
"stops": [
[
2,
1
],
[
6,
1.6
]
]
}
},
"filter": [
"all"
],
"layout": {
"text-font": [
"Open Sans Semibold"
],
"text-size": {
"stops": [
[
2,
10
],
[
4,
12
],
[
6,
16
]
]
},
"text-field": {
"stops": [
[
2,
"{ABBREV}"
],
[
4,
"{NAME}"
]
]
},
"visibility": "visible",
"text-max-width": 10,
"text-transform": {
"stops": [
[
0,
"uppercase"
],
[
2,
"none"
]
]
}
}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment