Skip to content

Commit

Permalink
feat: add geoData option as alternative to using geofile
Browse files Browse the repository at this point in the history
  • Loading branch information
dpraul committed Aug 5, 2019
1 parent 5ca0ed6 commit edff38f
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/js/geomap.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,18 @@ export class Geomap {
constructor() {
// Set default properties optimized for naturalEarth projection.
this.properties = {
/**
* URL to TopoJSON file to load when geomap is drawn. Ignored if geoData is specified.
*
* @type {string|null}
*/
geofile: null,
/**
* Contents of TopoJSON file. If specified, geofile is ignored.
*
* @type {object|null}
*/
geoData: null,
height: null,
postUpdate: null,
projection: geoNaturalEarth1,
Expand Down Expand Up @@ -106,7 +117,7 @@ export class Geomap {

self.path = geoPath().projection(proj);

d3JSONFetch(self.properties.geofile).then(geo => {
const drawGeoData = geo => {
self.geo = geo;
self.svg.append('g').attr('class', 'units zoom')
.selectAll('path')
Expand All @@ -118,7 +129,13 @@ export class Geomap {
.append('title')
.text(self.properties.unitTitle);
self.update();
});
};

if (self.properties.geoData) {
drawGeoData(self.properties.geoData);
} else {
d3JSONFetch(self.properties.geofile).then(geo => drawGeoData(geo));
}
}

update() {
Expand Down

0 comments on commit edff38f

Please sign in to comment.