mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-11 09:41:40 -05:00
Use local countries.geojson
This commit is contained in:
parent
dd91b581f5
commit
bc28babf15
5 changed files with 295 additions and 12 deletions
File diff suppressed because one or more lines are too long
|
|
@ -154,9 +154,20 @@ export default class extends Controller {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// the JSON is 23MB, so it's better to fetch it asynchronously or cache or use local copy
|
try {
|
||||||
const response = await fetch('https://raw.githubusercontent.com/datasets/geo-countries/master/data/countries.geojson')
|
// Up-to-date version can be found on Github:
|
||||||
const worldData = await response.json()
|
// https://raw.githubusercontent.com/datasets/geo-countries/master/data/countries.geojson
|
||||||
|
const response = await fetch('/countries.geojson', {
|
||||||
|
headers: {
|
||||||
|
'Accept': 'application/geo+json,application/json'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(`HTTP error! status: ${response.status}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const worldData = await response.json();
|
||||||
|
|
||||||
const visitedCountries = this.getVisitedCountries(countryCodesMap)
|
const visitedCountries = this.getVisitedCountries(countryCodesMap)
|
||||||
const filteredFeatures = worldData.features.filter(feature =>
|
const filteredFeatures = worldData.features.filter(feature =>
|
||||||
|
|
@ -167,7 +178,11 @@ export default class extends Controller {
|
||||||
type: 'FeatureCollection',
|
type: 'FeatureCollection',
|
||||||
features: filteredFeatures
|
features: filteredFeatures
|
||||||
})
|
})
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error loading GeoJSON:', error);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
getVisitedCountries(countryCodesMap) {
|
getVisitedCountries(countryCodesMap) {
|
||||||
if (!this.markers) return [];
|
if (!this.markers) return [];
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,10 @@ Rails.application.configure do
|
||||||
# Suppress logger output for asset requests.
|
# Suppress logger output for asset requests.
|
||||||
config.assets.quiet = true
|
config.assets.quiet = true
|
||||||
|
|
||||||
|
config.assets.content_type = {
|
||||||
|
geojson: 'application/geo+json'
|
||||||
|
}
|
||||||
|
|
||||||
# Raises error for missing translations.
|
# Raises error for missing translations.
|
||||||
# config.i18n.raise_on_missing_translations = true
|
# config.i18n.raise_on_missing_translations = true
|
||||||
|
|
||||||
|
|
|
||||||
3
config/initializers/mime_types.rb
Normal file
3
config/initializers/mime_types.rb
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
Mime::Type.register 'application/geo+json', :geojson
|
||||||
261
public/countries.geojson
Normal file
261
public/countries.geojson
Normal file
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue