-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathtopojson_utils.js
33 lines (25 loc) · 947 Bytes
/
topojson_utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
'use strict';
var topojsonUtils = module.exports = {};
var locationmodeToLayer = require('../plots/geo/constants').locationmodeToLayer;
var topojsonFeature = require('topojson-client').feature;
topojsonUtils.getTopojsonName = function(geoLayout) {
return [
geoLayout.scope.replace(/ /g, '-'), '_',
geoLayout.resolution.toString(), 'm'
].join('');
};
topojsonUtils.getTopojsonPath = function(topojsonURL, topojsonName) {
var path = topojsonURL;
if(topojsonName.startsWith('un_')) {
path += 'un';
return 'https://raw.githubusercontent.com/etpinard/sane-topojson/refs/heads/un-borders/dist/un.json';
} else {
path += topojsonName;
}
return path + '.json';
};
topojsonUtils.getTopojsonFeatures = function(trace, topojson) {
var layer = locationmodeToLayer[trace.locationmode];
var obj = topojson.objects[layer];
return topojsonFeature(topojson, obj).features;
};