From edff38f00cea20f3b029f0c76f2a4e26db26b4c8 Mon Sep 17 00:00:00 2001 From: Dylan Praul Date: Mon, 5 Aug 2019 16:45:48 -0400 Subject: [PATCH] feat: add geoData option as alternative to using geofile --- src/js/geomap.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/js/geomap.js b/src/js/geomap.js index 8f570a6..ade3246 100644 --- a/src/js/geomap.js +++ b/src/js/geomap.js @@ -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, @@ -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') @@ -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() {