leafem icon indicating copy to clipboard operation
leafem copied to clipboard

addFgb with minZoom != NULL throws error (addFlatGeoBufFiltered)

Open trafficonese opened this issue 1 year ago • 3 comments

This app will throw an error in the console. It happens with the CRAN and dev version.

APP

library(leafem)
library(leaflet)
library(shiny)
library(terra)
library(sf)

## Transform Data to FGB ############ 
linesdf <- st_as_sf(leaflet::atlStorms2005)
shp <- vect(linesdf)
shp_ext <- unname(as.vector(ext(shp)))
fgb_path <- tempfile(fileext = ".fgb")
writeVector(shp, fgb_path, filetype = "FlatGeobuf")

## UI ##################
ui <- fluidPage(leafletOutput("map", height = 700))

## SERVER ##################
server <- function(input, output){
  output$map <- renderLeaflet({
    leaflet("map") %>%
      fitBounds(shp_ext[1], shp_ext[3], shp_ext[2], shp_ext[4]) %>%
      leafem::addMouseCoordinates() %>% 
      addTiles(group = "Streets") %>%
      addFgb(fgb_path, 
             minZoom = 5,
             fill = FALSE
             )
  })
}

shinyApp(ui = ui, server = server)

VM40:1 Uncaught (in promise) TypeError: Cannot read properties of null (reading 'xyArray') at :1:25169 at x (:1:25380) at C (:1:28548) at :16:23137 at async updateResults (:348:24)

If I change minZoom = 2 then the layer will initially be loaded and visible, but as soon as you zoom in, the same error appears.

trafficonese avatar Jun 11 '24 15:06 trafficonese

I can reproduce this, but I have no clue what's causing this. All I know is that it used to work...

tim-salabim avatar Jun 13 '24 08:06 tim-salabim

Ok, this is weird. The xyArray error only comes when the DevTools are opened and the user interacts (zoom/pan) with the map. This happens in Brave, Chrome, Edge.

In Firefox it doesnt work at all and throws another error, although the example from flatgeobuf works in Firefox.

Uncaught (in promise) TypeError: t is null

Maybe this https://github.com/flatgeobuf/flatgeobuf/issues/245 is related?

And I am seeing much more console messages compared to the flatgeobuf example..

trafficonese avatar Jun 13 '24 08:06 trafficonese

Yeah, it's really strange. In this document from September 2022 everything works as expected, even in firefox (though there are pmtiles related errors when there's no tiles for a zoom level - but that's a different issue)

https://cn-vector-data-vis.s3.eu-central-1.amazonaws.com/cn-vector-data-vis.html

tim-salabim avatar Jun 13 '24 09:06 tim-salabim