Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

addGeoJSON() fails to render valid geometries #622

Closed
aoles opened this issue May 3, 2019 · 3 comments · Fixed by #625
Closed

addGeoJSON() fails to render valid geometries #622

aoles opened this issue May 3, 2019 · 3 comments · Fixed by #625
Labels
difficulty: novice Anyone could help effort: low < 1 day of work help wanted Solution is well-specified enough that any community member could fix priority: medium Could be fixed before next release

Comments

@aoles
Copy link
Contributor

aoles commented May 3, 2019

Hi,

it seems that geoJSON geometry primitives such as "Point" or "Polygon" are not displayed by addGeoJSON(). I would expect them to be valid input as according to the specification and to geojsonlint::geojson_validate() they conform to the standard.

Cheers,
Andrzej

library(leaflet)
library(jsonlite)
library(geojsonlint)

polygon = list(
  type = "Polygon",
  coordinates = list(
    list(
      c(8.330469, 48.261570),
      c(8.339052, 48.261570),
      c(8.339052, 48.258227),
      c(8.330469, 48.258227),
      c(8.330469, 48.261570)
    )
  )
)

geojson_validate(toJSON(polygon, auto_unbox = TRUE))
#> [1] TRUE

leaflet() %>%
  addTiles() %>%
  addGeoJSON(polygon, color="#F00") %>%
  setView(lng = 8.330469, lat = 48.26157, zoom = 15)

feature <- list(
  type = "Feature",
  properties = "",
  geometry = polygon
)

leaflet() %>%
  addTiles() %>%
  addGeoJSON(feature, color="#F00") %>%
  setView(lng = 8.330469, lat = 48.26157, zoom = 15)

Created on 2019-05-03 by the reprex package (v0.2.1)

@schloerke
Copy link
Contributor

This line is causing the issue:

let popup = feature.properties.popup;

@schloerke
Copy link
Contributor

Check to make sure properties is not undefined. Or use extraInfo object properties

@schloerke schloerke added difficulty: novice Anyone could help effort: low < 1 day of work help wanted Solution is well-specified enough that any community member could fix priority: medium Could be fixed before next release labels May 7, 2019
@schloerke schloerke assigned schloerke and jcheng5 and unassigned schloerke and jcheng5 May 29, 2019
@jcheng5
Copy link
Member

jcheng5 commented May 29, 2019

Thanks, @aoles! Just one nit with this example: properties = "" isn't valid GeoJSON, that should either be null or {}. (But I think the PR is fine despite this, since both "" and null are falsy)

@schloerke schloerke mentioned this issue May 29, 2019
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
difficulty: novice Anyone could help effort: low < 1 day of work help wanted Solution is well-specified enough that any community member could fix priority: medium Could be fixed before next release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants