+ // resolveLocation
+ //
+ // Pass a `location` identifier
+ // Returns a result like
+ // {
+ // type: 'point', 'geojson', or 'countrycoder'
+ // location:the queried location
+ // id: a unique identifier
+ // feature: the geojson feature
+ // }
+ //or `null` if the location is invalid
+ //
+ defaultExport.prototype.resolveLocation = function resolveLocation (location) {
+ var valid = this.validateLocation(location);
+ if (!valid) { return null; }
+
+ // return a result from cache if we can
+ if (this._cache[valid.id]) {
+ return Object.assign(valid, { feature: this._cache[valid.id] });
+ }
+
+ // a [lon,lat] coordinate pair?
+ if (valid.type === 'point') {
+ var RADIUS = 25000;// meters
+ var EDGES = 10;
+ var PRECISION = 3;
+ var area = Math.PI * RADIUS * RADIUS / 1e6; // m² to km²
+ var feature$1 = this._cache[valid.id] = geojsonPrecision({
+ type: 'Feature',
+ id: valid.id,
+ properties: { id: valid.id, area: Number(area.toFixed(2)) },
+ geometry: circleToPolygon(location, RADIUS, EDGES)
+ }, PRECISION);
+ return Object.assign(valid, { feature: feature$1 });
+
+ // a .geojson filename?
+ } else if (valid.type === 'geojson') ; else if (valid.type === 'countrycoder') {
+ var feature$1$1 = _cloneDeep(feature(valid.id));
+ var props = feature$1$1.properties;
+
+ // -> This block of code is weird and requires some explanation. <-
+ // CountryCoder includes higher level features which are made up of members.
+ // These features don't have their own geometry, but CountryCoder provides an
+ // `aggregateFeature` method to combine these members into a MultiPolygon.
+ // BUT, when we try to actually work with these aggregated MultiPolygons,
+ // Turf/JSTS gets crashy because of topography bugs.
+ // SO, we'll aggregate the features ourselves by unioning them together.
+ // This approach also has the benefit of removing all the internal boaders and
+ // simplifying the regional polygons a lot.
+ if (Array.isArray(props.members)) {
+ var seed = feature$1$1.geometry ? feature$1$1 : null;
+ var aggregate = props.members.reduce(_locationReducer.bind(this), seed);
+ feature$1$1.geometry = aggregate.geometry;
+ }
+
+ // ensure area property exists
+ if (!props.area) {
+ var area$1 = geojsonArea.geometry(feature$1$1.geometry) / 1e6;// m² to km²
+ props.area = Number(area$1.toFixed(2));
+ }
+
+ // ensure id property exists
+ feature$1$1.id = valid.id;
+ props.id = valid.id;
+
+ this._cache[valid.id] = feature$1$1;
+ return Object.assign(valid, { feature: feature$1$1 });