mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-09 19:09:00 -05:00
Use local countries.geojson
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -154,21 +154,36 @@ export default class extends Controller {
|
||||
}
|
||||
})
|
||||
|
||||
// the JSON is 23MB, so it's better to fetch it asynchronously or cache or use local copy
|
||||
const response = await fetch('https://raw.githubusercontent.com/datasets/geo-countries/master/data/countries.geojson')
|
||||
const worldData = await response.json()
|
||||
try {
|
||||
// Up-to-date version can be found on Github:
|
||||
// https://raw.githubusercontent.com/datasets/geo-countries/master/data/countries.geojson
|
||||
const response = await fetch('/countries.geojson', {
|
||||
headers: {
|
||||
'Accept': 'application/geo+json,application/json'
|
||||
}
|
||||
});
|
||||
|
||||
const visitedCountries = this.getVisitedCountries(countryCodesMap)
|
||||
const filteredFeatures = worldData.features.filter(feature =>
|
||||
visitedCountries.includes(feature.properties.ISO_A2)
|
||||
)
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
|
||||
this.scratchLayer.addData({
|
||||
type: 'FeatureCollection',
|
||||
features: filteredFeatures
|
||||
})
|
||||
const worldData = await response.json();
|
||||
|
||||
const visitedCountries = this.getVisitedCountries(countryCodesMap)
|
||||
const filteredFeatures = worldData.features.filter(feature =>
|
||||
visitedCountries.includes(feature.properties.ISO_A2)
|
||||
)
|
||||
|
||||
this.scratchLayer.addData({
|
||||
type: 'FeatureCollection',
|
||||
features: filteredFeatures
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('Error loading GeoJSON:', error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
getVisitedCountries(countryCodesMap) {
|
||||
if (!this.markers) return [];
|
||||
|
||||
|
||||
@@ -64,6 +64,10 @@ Rails.application.configure do
|
||||
# Suppress logger output for asset requests.
|
||||
config.assets.quiet = true
|
||||
|
||||
config.assets.content_type = {
|
||||
geojson: 'application/geo+json'
|
||||
}
|
||||
|
||||
# Raises error for missing translations.
|
||||
# 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
Reference in New Issue
Block a user