Skip to content

Leaflet map html fails to render in browser with AddGraticule() "Uncaught TypeError: can't access property "x", o is undefined" #963

@jjookkii

Description

@jjookkii

Hello,

Firefox 145.0.2 fails to render saved *.html leaflet map saved from R Studio with htmlwidgets:saveWidget() due to Uncaught TypeError: can't access property "x", o is undefined. The same *.html leaflet map is rendered by previous Firefox versions, Edge browser and R Studio viewer. Something changed in Firefox JS execution to be more sensitive to misc errors.

Map renders without leaflet:AddGraticule() function, but fails with it, thus error likely related to AddGraticule() initialization in browser.
Tested with R 4.1.3, R.4.4.3. leaflet package 2.2.1 & 2.2.3. *.html always seems to fail on the same error in Firefox. Removing AddGraticule() works in Firefox.

Is there some error with leaflet:AddGraticule() implementation?

Firefox console shows error Uncaught TypeError: can't access property "x", o is undefined which is traced to lines with s=o.x in saved *.html page code

intersects:function(t){
  t=b(t);
  var i=this.min,e=this.max,
  n=t.min,o=t.max,
  s=o.x>=i.x&&n.x<=e.x, 
  r=o.y>=i.y&&n.y<=e.y;
  return s&&r
},

#############
# reproducible example in R Studio
#############

library(leaflet)
library(htmlwidgets)

m <- leaflet(options = leafletOptions(
  preferCanvas = T
)) %>%
  addTiles() %>%
  addGraticule(
    interval = 20,
    sphere = FALSE,
    style = list(color = "#333", weight = 1, opacity = 0.25),
    layerId = NULL,
    group = NULL,
    options = pathOptions(pointerEvents = "none", clickable = FALSE)
  )
m # (should show a world map with gridlines)

saveWidget(m, file = "leaflet_map.html", selfcontained = T, title = "AddGraticule")
# test if *.html is rendered the same in browser as in R Studio viewer
# check errors in browser console

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions