Skip to content

Commit

Permalink
Merge pull request #2 from PopulateTools/filter_geometry_and_check_co…
Browse files Browse the repository at this point in the history
…nfig_map

Checks if the viewer has the map-config and filtered the geometry column
  • Loading branch information
jorgeatgu authored May 18, 2021
2 parents 7742ff5 + 4e0733d commit d5950dd
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,16 @@ export class MapPlugin {
try {
const columns = JSON.parse(this.getAttribute("columns"))
const geomColumn = this.getAttribute("geom") || "geometry" // default geoJSON column name
const { metric: mapMetric, zoom: mapZoom = false } = JSON.parse(this.getAttribute("config-map") || {}) || {}

let mapZoom = false
let mapMetric

//Checks if the config object has been declared
if(this.getAttribute("config-map") !== null) {
const { metric, zoom } = JSON.parse(this.getAttribute("config-map")) || {}
mapMetric = metric
mapZoom = zoom || false
}

// Enforces to have a geometry column
if (!columns.includes(geomColumn)) {
Expand All @@ -113,7 +122,9 @@ export class MapPlugin {
const map = createMapNode(this, div, { zoom: mapZoom });

// fetch the current displayed data
const data = await view.to_json() || []
let data = await view.to_json() || []
//Some datasets may come with an empty geometry field, so we have to filter them to avoid errors.
data = data.filter(({ geometry }) => !!geometry)
if (data.some(({ [geomColumn]: geometry }) => !!geometry)) {

// get the first [key, value] from the dataset to determine its type
Expand Down

0 comments on commit d5950dd

Please sign in to comment.