Offline regions for the whole world: the region list comes from Geofabrik's index (bin/geofabrik-regions-sync.mjs → geofabrik_regions.geojson, 193 countries plus subregions like the US states), keeping the European ISO codes; the picker folds it by continent with a search box and subregions under their country, flags for all of them
This commit is contained in:
1 parent
df69886220
commit
ff5924faf1
155 files changed
+5465
-113
No files matched your search
@@ -1 +0,0 @@
|
||||
{"type":"FeatureCollection","features":[{"type":"Feature","properties":{"name":"Albania","iso_a2":"AL","iso_a3":"ALB"},"geometry":{"type":"Polygon","coordinates":[[[21.02004,40.842727],[20.99999,40.580004],[20.674997,40.435],[20.615,40.110007],[20.150016,39.624998],[19.98,39.694993],[19.960002,39.915006],[19.406082,40.250773],[19.319059,40.72723],[19.40355,41.409566],[19.540027,41.719986],[19.371769,41.877548],[19.371768,41.877551],[19.304486,42.195745],[19.738051,42.688247],[19.801613,42.500093],[20.0707,42.58863],[20.283755,42.32026],[20.52295,42.21787],[20.590247,41.855409],[20.590247,41.855404],[20.463175,41.515089],[20.605182,41.086226],[21.02004,40.842727]]]}},{"type":"Feature","properties":{"name":"Austria","iso_a2":"AT","iso_a3":"AUT"},"geometry":{"type":"Polygon","coordinates":[[[16.979667,48.123497],[16.903754,47.714866],[16.340584,47.712902],[16.534268,47.496171],[16.202298,46.852386],[16.011664,46.683611],[15.137092,46.658703],[14.632472,46.431817],[13.806475,46.509306],[12.376485,46.767559],[12.153088,47.115393],[11.164828,46.941579],[11.048556,46.751359],[10.442701,46.893546],[9.932448,46.920728],[9.47997,47.10281],[9.632932,47.347601],[9.594226,47.525058],[9.896068,47.580197],[10.402084,47.302488],[10.544504,47.566399],[11.426414,47.523766],[12.141357,47.703083],[12.62076,47.672388],[12.932627,47.467646],[13.025851,47.637584],[12.884103,48.289146],[13.243357,48.416115],[13.595946,48.877172],[14.338898,48.555305],[14.901447,48.964402],[15.253416,49.039074],[16.029647,48.733899],[16.499283,48.785808],[16.960288,48.596982],[16.879983,48.470013],[16.979667,48.123497]]]}},{"type":"Feature","properties":{"name":"Belarus","iso_a2":"BY","iso_a3":"BLR"},"geometry":{"type":"Polygon","coordinates":[[[28.176709,56.16913],[29.229513,55.918344],[29.371572,55.670091],[29.896294,55.789463],[30.873909,55.550976],[30.971836,55.081548],[30.757534,54.811771],[31.384472,54.157056],[31.791424,53.974639],[31.731273,53.794029],[32.405599,53.618045],[32.693643,53.351421],[32.304519,53.132726],[31.49764,53.16743],[31.305201,53.073996],[31.540018,52.742052],[31.78597,52.10168],[31.785992,52.101678],[30.927549,52.042353],[30.619454,51.822806],[30.555117,51.319503],[30.157364,51.416138],[29.254938,51.368234],[28.992835,51.602044],[28.617613,51.427714],[28.241615,51.572227],[27.454066,51.592303],[26.337959,51.832289],[25.327788,51.910656],[24.553106,51.888461],[24.005078,51.617444],[23.527071,51.578454],[23.508002,52.023647],[23.199494,52.486977],[23.799199,52.691099],[23.804935,53.089731],[23.527536,53.470122],[23.484128,53.912498],[24.450684,53.905702],[25.536354,54.282423],[25.768433,54.846963],[26.588279,55.167176],[26.494331,55.615107],[27.10246,55.783314],[28.176709,56.16913]]]}},{"type":"Feature","properties":{"name":"Belgium","iso_a2":"BE","iso_a3":"BEL"},"geometry":{"type":"Polygon","coordinates":[[[6.156658,50.803721],[6.043073,50.128052],[5.782417,50.090328],[5.674052,49.529484],[4.799222,49.985373],[4.286023,49.907497],[3.588184,50.378992],[3.123252,50.780363],[2.658422,50.796848],[2.513573,51.148506],[3.314971,51.345781],[3.315011,51.345777],[3.314971,51.345755],[4.047071,51.267259],[4.973991,51.475024],[5.606976,51.037298],[6.156658,50.803721]]]}},{"type":"Feature","properties":{"name":"Bosnia and Herz.","iso_a2":"BA","iso_a3":"BIH"},"geometry":{"type":"Polygon","coordinates":[[[18.56,42.65],[17.674922,43.028563],[17.297373,43.446341],[16.916156,43.667722],[16.456443,44.04124],[16.23966,44.351143],[15.750026,44.818712],[15.959367,45.233777],[16.318157,45.004127],[16.534939,45.211608],[17.002146,45.233777],[17.861783,45.06774],[18.553214,45.08159],[19.005485,44.860234],[19.00548,44.86023],[19.36803,44.863],[19.11761,44.42307],[19.59976,44.03847],[19.454,43.5681],[19.21852,43.52384],[19.03165,43.43253],[18.70648,43.20011],[18.56,42.65]]]}},{"type":"Feature","properties":{"name":"Bulgaria","iso_a2":"BG","iso_a3":"BGR"},"geometry":{"type":"Polygon","coordinates":[[[22.65715,44.234923],[22.944832,43.823785],[23.332302,43.897011],[24.100679,43.741051],[25.569272,43.688445],[26.065159,43.943494],[27.2424,44.175986],[27.970107,43.812468],[28.558081,43.707462],[28.039095,43.293172],[27.673898,42.577892],[27.99672,42.007359],[27.135739,42.141485],[26.117042,41.826905],[26.106138,41.328899],[25.197201,41.234486],[24.492645,41.583896],[23.692074,41.309081],[22.952377,41.337994],[22.881374,41.999297],[22.380526,42.32026],[22.545012,42.461362],[22.436595,42.580321],[22.604801,42.898519],[22.986019,43.211161],[22.500157,43.642814],[22.410446,44.008063],[22.65715,44.234923]]]}},{"type":"Feature","properties":{"name":"Croatia","iso_a2":"HR","iso_a3":"HRV"},"geometry":{"type":"Polygon","coordinates":[[[16.564808,46.503751],[16.882515,46.380632],[17.630066,45.951769],[18.456062,45.759481],[18.829825,45.908872],[19.072769,45.521511],[19.390476,45.236516],[19.005485,44.860234],[18.553214,45.08159],[17.861783,45.06774],[17.002146,45.233777],[16.534939,45.211608],[16.318157,45.004127],[15.959367,45.233777],[15.750026,44.818712],[Line truncated
|
||||
@@ -0,0 +1 @@
|
||||
{"type":"FeatureCollection","continents":[{"id":"europe","name":"Europe"},{"id":"north-america","name":"North America"},{"id":"central-america","name":"Central America"},{"id":"south-america","name":"South America"},{"id":"asia","name":"Asia"},{"id":"russia","name":"Russia"},{"id":"africa","name":"Africa"},{"id":"australia-oceania","name":"Australia and Oceania"},{"id":"antarctica","name":"Antarctica"}],"features":[{"type":"Feature","properties":{"code":"AF","name":"Afghanistan","slug":"asia/afghanistan","continent":"asia"},"geometry":{"type":"MultiPolygon","coordinates":[[[[62.4748,29.3819],[60.8505,29.8583],[61.7868,30.8377],[61.7675,30.9246],[61.8225,31.0412],[61.7892,31.1795],[61.7492,31.2399],[61.7028,31.3631],[60.8286,31.4898],[60.7945,31.6517],[60.8129,31.7388],[60.7918,31.8578],[60.8044,31.941],[60.7796,32.0351],[60.8186,32.1026],[60.839,32.2353],[60.5642,33.0668],[60.4876,33.7385],[60.5353,33.8197],[60.4902,34.1405],[60.5314,34.2067],[60.7068,34.5337],[60.7443,34.5674],[60.8411,34.5837],[60.9035,34.6506],[60.9682,34.7415],[61.053,34.9325],[61.0783,35.1777],[61.0764,35.2639],[61.107,35.2987],[61.1778,35.4069],[61.2474,35.5333],[61.2625,35.6249],[61.3871,35.6493],[61.4261,35.5759],[61.6036,35.462],[61.7917,35.4325],[61.9597,35.4767],[62.0413,35.463],[62.165,35.3576],[62.2756,35.3063],[62.3065,35.2626],[62.3167,35.1736],[62.4604,35.3048],[62.5181,35.2914],[62.5679,35.2517],[62.6269,35.2466],[62.71,35.2704],[62.9059,35.3963],[63.1023,35.5328],[63.0822,35.5546],[63.0789,35.6324],[63.198,35.6997],[63.1156,35.7657],[63.0863,35.8268],[63.1088,35.8759],[63.3166,35.8709],[63.599,35.9826],[63.7699,35.9976],[63.8812,36.0485],[63.969,36.0581],[64.0555,36.1123],[64.1566,36.1808],[64.3257,36.2394],[64.6053,36.4494],[64.5983,36.6359],[64.7785,36.9327],[64.7122,37.1297],[65.0723,37.2625],[65.2371,37.2489],[65.5402,37.2712],[65.6282,37.3591],[65.6281,37.4576],[65.6651,37.5257],[65.7034,37.5552],[65.755,37.5523],[65.7789,37.5878],[65.8603,37.5186],[66.0933,37.45],[66.2255,37.3911],[66.2962,37.3442],[66.4078,37.3634],[66.448,37.3407],[66.5831,37.3872],[66.6947,37.375],[66.8428,37.3743],[66.956,37.4146],[67.0686,37.3871],[67.1269,37.3372],[67.1369,37.292],[67.2275,37.2629],[67.2635,37.2058],[67.407,37.2389],[67.4946,37.2867],[67.5677,37.2428],[67.6046,37.2552],[67.7344,37.2342],[67.8034,37.1849],[67.8007,37.106],[67.8942,37.0766],[68.0253,36.9445],[68.175,37.0348],[68.2611,37.0276],[68.2619,37.0905],[68.2866,37.1232],[68.3974,37.1597],[68.5292,37.2084],[68.5996,37.2188],[68.6567,37.2906],[68.7601,37.2947],[68.7965,37.2779],[68.7987,37.3348],[68.8837,37.3547],[69.0041,37.326],[69.1334,37.1827],[69.2226,37.1321],[69.304,37.1373],[69.3875,37.181],[69.41,37.2179],[69.366,37.3359],[69.3654,37.4587],[69.5062,37.5952],[69.6466,37.5894],[69.7338,37.6142],[69.8006,37.6021],[69.9042,37.6324],[70.0215,37.5636],[70.142,37.5521],[70.2021,37.6267],[70.2411,37.6357],[70.2738,37.7012],[70.2556,37.803],[70.1695,37.8439],[70.1617,37.9462],[70.2442,37.962],[70.2509,37.9909],[70.3543,38.0686],[70.5321,38.2543],[70.5969,38.356],[70.6606,38.3765],[70.674,38.4272],[70.7349,38.438],[70.7664,38.4721],[70.8409,38.4681],[70.878,38.4857],[70.9252,38.4568],[70.9354,38.4883],[70.9881,38.5067],[71.0408,38.4752],[71.1149,38.4362],[71.2285,38.3422],[71.3409,38.32],[71.39,38.2622],[71.3926,38.1554],[71.3559,38.1197],[71.2885,37.9496],[71.34,37.9118],[71.5355,37.9695],[71.606,37.9284],[71.6121,37.8008],[71.5628,37.7605],[71.5677,37.7123],[71.5159,37.5451],[71.5429,37.4752],[71.5061,37.3913],[71.5076,37.2781],[71.4674,37.2034],[71.4497,37.0691],[71.4803,36.9978],[71.4795,36.9428],[71.5462,36.857],[71.5675,36.7786],[71.6753,36.6954],[71.8392,36.7023],[72.0127,36.8281],[72.3373,37.0058],[72.6563,37.0405],[72.8012,37.2433],[73.0726,37.3355],[73.1401,37.4173],[73.2136,37.4262],[73.3074,37.4821],[73.3837,37.4696],[73.517,37.4917],[73.6314,37.4558],[73.7844,37.455],[74.2335,37.4306],[74.3629,37.4417],[74.4121,37.4118],[74.4682,37.4438],[74.579,37.396],[74.6967,37.4216],[74.8195,37.3649],[74.9002,37.2699],[74.8974,37.2079],[74.8287,37.197],[74.799,37.2008],[74.7382,37.2644],[74.6609,37.2174],[74.5774,37.2183],[74.5227,37.2237],[74.4875,37.14],[74.58,37.0403],[74.5481,37.0059],[74.5524,36.9506],[74.5171,36.9426],[74.439,36.9835],[74.3045,36.8973],[74.2366,36.8779],[74.124,36.8213],[73.9796,36.8153],[73.6824,36.8959],[73.5431,36.8555],[73.303,36.8524],[73.0832,36.8669],[73.0419,36.8422],[72.963,36.8534],[72.9356,36.8269],[72.8908,36.8221],[72.6451,36.8285],[72.5745,36.8105],[72.5014,36.7616],[72.2526,36.7287],[72.2138,36.7015],[72.22,36.6484],[72.091,36.5738],[71.956,36.5327],[71.9174,36.491],[71.8223,36.4858],[71.8468,36.432],[71.8111,36.383],[71.6296,36.3929],[71.594,36.367],[71.605,36.3493],[71.588,36.3147],[71.5404,36.3073],[71.3558,36.1527],[71.2736,36.1186],[71.2229,36.0508],[71.3345,35.9815],[71.3948,35.9695],[71.4431,35.9004],[71.5183,35.8094],[71.567,35.7336],[71.6338,35.5817],[71.6742,35.4444],[71.5734,35.3019],[71.6983,35.2087],[71.6346,35.1251],[71.5Line truncated
|
||||
@@ -11,7 +11,7 @@ require_relative "places"
|
||||
module Maptool
|
||||
# Regenerates data/offline.pmtiles and data/terrain.pmtiles for the
|
||||
# currently *selected* regions (data/offline_regions.json, an array of
|
||||
# Natural Earth iso_a2 country codes — see available_regions/
|
||||
# region codes from REGIONS_FILE — see available_regions/
|
||||
# selected_regions/set_selected_regions below). No job queue: each build
|
||||
# runs on its own background Thread and reports into a Mutex-guarded
|
||||
# status Hash a route can poll, the same shape app.rb's own GNSS poller
|
||||
@@ -19,73 +19,23 @@ module Maptool
|
||||
module PmtilesBuilder
|
||||
class BuildError < StandardError; end
|
||||
|
||||
# Natural Earth (public domain, no attribution required) 110m admin-0
|
||||
# countries, filtered to Europe and trimmed to name/iso_a2/iso_a3 —
|
||||
# see the plan this was built from for the exact filter. 110m is
|
||||
# deliberately coarse (a km or so of border precision, not
|
||||
# survey-grade) — fine for "which country to grab," a same-schema swap
|
||||
# to Natural Earth's 50m/10m cut if that ever needs to be tighter.
|
||||
REGIONS_FILE = File.join(__dir__, "data", "europe_countries.geojson")
|
||||
|
||||
# Every iso_a2 code in REGIONS_FILE mapped to its Geofabrik download
|
||||
# slug (https://download.geofabrik.de/<slug>-latest.osm.pbf) — Geofabrik
|
||||
# names regions, not ISO codes, and doesn't always split the way a
|
||||
# country border does, so this table exists rather than deriving the
|
||||
# slug from the country name. Two known quirks worth knowing about,
|
||||
# not worth working around:
|
||||
# - RU has no "europe/" prefix (Russia is its own top-level index,
|
||||
# and unlike every other entry here is a single ~4GB file covering
|
||||
# the whole country rather than a European-only slice).
|
||||
# - GB's "great-britain" slug is England/Scotland/Wales only —
|
||||
# Northern Ireland lives in "ireland-and-northern-ireland" instead
|
||||
# (bundled with IE, not GB). Selecting GB alone won't include NI.
|
||||
GEOFABRIK_SLUGS = {
|
||||
"AL" => "europe/albania",
|
||||
"AT" => "europe/austria",
|
||||
"BY" => "europe/belarus",
|
||||
"BE" => "europe/belgium",
|
||||
"BA" => "europe/bosnia-herzegovina",
|
||||
"BG" => "europe/bulgaria",
|
||||
"HR" => "europe/croatia",
|
||||
"CZ" => "europe/czech-republic",
|
||||
"DK" => "europe/denmark",
|
||||
"EE" => "europe/estonia",
|
||||
"FI" => "europe/finland",
|
||||
"FR" => "europe/france",
|
||||
"DE" => "europe/germany",
|
||||
"GR" => "europe/greece",
|
||||
"HU" => "europe/hungary",
|
||||
"IS" => "europe/iceland",
|
||||
"IE" => "europe/ireland-and-northern-ireland",
|
||||
"IT" => "europe/italy",
|
||||
"XK" => "europe/kosovo",
|
||||
"LV" => "europe/latvia",
|
||||
"LT" => "europe/lithuania",
|
||||
"LU" => "europe/luxembourg",
|
||||
"MD" => "europe/moldova",
|
||||
"ME" => "europe/montenegro",
|
||||
"NL" => "europe/netherlands",
|
||||
"MK" => "europe/macedonia",
|
||||
"NO" => "europe/norway",
|
||||
"PL" => "europe/poland",
|
||||
"PT" => "europe/portugal",
|
||||
"RO" => "europe/romania",
|
||||
"RU" => "russia",
|
||||
"RS" => "europe/serbia",
|
||||
"SK" => "europe/slovakia",
|
||||
"SI" => "europe/slovenia",
|
||||
"ES" => "europe/spain",
|
||||
"SE" => "europe/sweden",
|
||||
"CH" => "europe/switzerland",
|
||||
"UA" => "europe/ukraine",
|
||||
"GB" => "europe/great-britain",
|
||||
}.freeze
|
||||
# Every region the offline map can be built from: Geofabrik's own index
|
||||
# (download.geofabrik.de/index-v1.json), trimmed by
|
||||
# bin/geofabrik-regions-sync.mjs to the countries per continent plus one
|
||||
# level of subregions (US states, German Länder, ...). Each feature has a
|
||||
# code (a country's ISO 3166-1 alpha-2 — the codes the old Europe-only
|
||||
# list used, so caches/selections carry over — a subregion's ISO 3166-2
|
||||
# code or <country>-<id>, else the Geofabrik id), its name, its Geofabrik
|
||||
# path (https://download.geofabrik.de/<slug>-latest.osm.pbf), continent,
|
||||
# parent country for a subregion, and its boundary polygon (Geofabrik's
|
||||
# own clip polygon — what terrain extraction clips to).
|
||||
REGIONS_FILE = File.join(__dir__, "data", "geofabrik_regions.geojson")
|
||||
|
||||
# Mapterhorn (a Protomaps-affiliated project) publishes Terrarium-
|
||||
# encoded terrain as pre-built PMTiles archives: one global
|
||||
# planet.pmtiles (z0-12) plus ~450 regional chunks (z13 up to a
|
||||
# per-region max, 13-18) — extract_offline below no longer touches
|
||||
# Protomaps at all (see GEOFABRIK_SLUGS above), but terrain stays on
|
||||
# Protomaps at all (Geofabrik extracts, see REGIONS_FILE), but terrain stays on
|
||||
# this same "extract only the region's byte ranges from a remote
|
||||
# archive" story via go-pmtiles, unrelated to the basemap swap.
|
||||
MAPTERHORN_MANIFEST_URL = "https://download.mapterhorn.com/download_urls.json"
|
||||
@@ -170,8 +120,17 @@ module Maptool
|
||||
|
||||
# --- region selection ---
|
||||
|
||||
# [{code:, name:, continent:, parent:}] — parent is nil for a country.
|
||||
def self.available_regions
|
||||
region_features.map { |f| { code: f["properties"]["iso_a2"], name: f["properties"]["name"] } }.sort_by { |r| r[:name] }
|
||||
region_features.map do |f|
|
||||
p = f["properties"]
|
||||
{ code: p["code"], name: p["name"], continent: p["continent"], parent: p["parent"] }
|
||||
end.sort_by { |r| r[:name] }
|
||||
end
|
||||
|
||||
# [{id:, name:}] in the picker's order.
|
||||
def self.continents
|
||||
region_catalog["continents"]
|
||||
end
|
||||
|
||||
def self.selected_regions(data_dir)
|
||||
@@ -195,11 +154,21 @@ module Maptool
|
||||
end
|
||||
private_class_method :selected_regions_path
|
||||
|
||||
def self.region_catalog
|
||||
@region_catalog ||= JSON.parse(File.read(REGIONS_FILE))
|
||||
end
|
||||
private_class_method :region_catalog
|
||||
|
||||
def self.region_features
|
||||
@region_features ||= JSON.parse(File.read(REGIONS_FILE))["features"]
|
||||
region_catalog["features"]
|
||||
end
|
||||
private_class_method :region_features
|
||||
|
||||
def self.geofabrik_slug(code)
|
||||
region_features.find { |f| f["properties"]["code"] == code }&.dig("properties", "slug")
|
||||
end
|
||||
private_class_method :geofabrik_slug
|
||||
|
||||
# Still used by terrain (below) to compute the aggregate bbox Mapterhorn
|
||||
# chunk intersection needs — offline.pmtiles no longer needs this at
|
||||
# all, since each Geofabrik country file is already clipped to that
|
||||
@@ -207,7 +176,7 @@ module Maptool
|
||||
# less), so there's no separate "--region=" precision step for it
|
||||
# anymore.
|
||||
def self.region_bbox(codes)
|
||||
selected = region_features.select { |f| codes.include?(f["properties"]["iso_a2"]) }
|
||||
selected = region_features.select { |f| codes.include?(f["properties"]["code"]) }
|
||||
raise BuildError, "no matching regions for #{codes.join(", ")}" if selected.empty?
|
||||
|
||||
coords = selected.flat_map { |f| ring_coordinates(f["geometry"]) }
|
||||
@@ -346,7 +315,7 @@ module Maptool
|
||||
def self.extract_offline(codes, data_dir, download_extract, fetch_last_modified, report_step)
|
||||
scratch_dir = Dir.mktmpdir("maptool-offline")
|
||||
sources = codes.each_with_index.map do |code, i|
|
||||
slug = GEOFABRIK_SLUGS.fetch(code) { raise BuildError, "no Geofabrik source known for region #{code}" }
|
||||
slug = geofabrik_slug(code) or raise BuildError, "no Geofabrik source known for region #{code}"
|
||||
report_step.call(progress_step("fetching #{code}", codes, i))
|
||||
cached_extract(code, slug, data_dir, download_extract, fetch_last_modified)
|
||||
end
|
||||
@@ -613,7 +582,7 @@ module Maptool
|
||||
return nil if codes.empty?
|
||||
|
||||
current = codes.map do |code|
|
||||
slug = GEOFABRIK_SLUGS[code]
|
||||
slug = geofabrik_slug(code)
|
||||
return nil unless slug
|
||||
|
||||
{ "code" => code, "last_modified" => fetch_last_modified.call(geofabrik_url(slug)) }
|
||||
@@ -662,6 +631,8 @@ module Maptool
|
||||
def self.delete_cached_extract(data_dir, code)
|
||||
OFFLINE_MUTEX.synchronize { raise BuildError, "a build is already running" if OFFLINE_STATUS[:state] == "running" }
|
||||
|
||||
raise BuildError, "unknown region #{code}" unless geofabrik_slug(code)
|
||||
|
||||
cache_dir = geofabrik_cache_dir(data_dir)
|
||||
path = File.join(cache_dir, "#{code}.osm.pbf")
|
||||
File.delete(path) if File.exist?(path)
|
||||
@@ -713,7 +684,7 @@ module Maptool
|
||||
scratch_dir = Dir.mktmpdir("maptool-terrain")
|
||||
south, west, north, east = region_bbox(codes)
|
||||
region_path = File.join(scratch_dir, "region.geojson")
|
||||
selected = region_features.select { |f| codes.include?(f["properties"]["iso_a2"]) }
|
||||
selected = region_features.select { |f| codes.include?(f["properties"]["code"]) }
|
||||
File.write(region_path, JSON.generate(type: "FeatureCollection", features: selected))
|
||||
|
||||
chunks = items.select { |item| item["name"] != MAPTERHORN_PLANET_NAME && bbox_intersects?(item, south, west, north, east) }
|
||||
|
||||
Reference in new issue
Block a user