Skip to content

Commit 20c2679

Browse files
committed
Reduce size of worldGeo data
1 parent b44de4c commit 20c2679

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

src/geoProjections.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,29 @@
2222
* const [x, y] = geo.projections.mercator([lon, lat], width, height, [centerLon, centerLat]);
2323
* const bounds = geo.getProjectedBounds(geo.projections.mercator, features, width, height, [0, 0]);
2424
*/
25+
26+
function simplifyGeoJSON(geoJson, keepProps = []) {
27+
const simplifiedFeatures = geoJson.features.map(feature => {
28+
const props = {};
29+
keepProps.forEach(key => {
30+
if (feature.properties && feature.properties.hasOwnProperty(key)) {
31+
props[key] = feature.properties[key];
32+
}
33+
});
34+
35+
return {
36+
type: 'Feature',
37+
geometry: feature.geometry,
38+
properties: props
39+
};
40+
});
41+
42+
return {
43+
type: 'FeatureCollection',
44+
features: simplifiedFeatures
45+
};
46+
}
47+
2548
const projections = {
2649
mercator([lon, lat], width, height, center) {
2750
const maxLat = 85.05113;
@@ -308,7 +331,8 @@ function setupTerritories(config, geoData) {
308331
const geo = {
309332
projections,
310333
getProjectedBounds,
311-
setupTerritories
334+
setupTerritories,
335+
simplifyGeoJSON
312336
}
313337

314338
export default geo

src/resources/worldGeo.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)