【发布时间】:2023-03-03 17:18:02
【问题描述】:
我正在寻找有关获取leafletR 包的基本示例以在浏览器中显示地图的指导。使用最基本的示例,地图不会显示在浏览器中。我检查了 .html 和 .json 文件,它们存在并且格式正确。 Javascript 检查器显示此错误:
XMLHttpRequest cannot load file:///var/folders/_0/tdgf_k7x77qdn64_gk9ynljm0000gp/T/Rtmp6O4QZM/Fiji_Earthquakes/quakes.geojson. Received an invalid response. Origin 'null' is therefore not allowed access.
我在 Mac 上:OSX 10.7.5 RStudio 版本:0.98.857
代码
library(leafletR)
data(quakes)
# store data in GeoJSON file (just a subset here)
q.dat <- toGeoJSON(data=quakes[1:99,], dest=tempdir(), name="quakes")
# make style based on quake magnitude
q.style <- styleGrad(prop="mag", breaks=seq(4, 6.5, by=0.5), style.val=rev(heat.colors(5)), leg="Richter Magnitude", fill.alpha=0.7, rad=8)
# create map
q.map <- leaflet(data=q.dat, dest=tempdir(), title="Fiji Earthquakes", base.map="osm", style=q.style, popup="mag")
# view map in browser
browseURL(q.map)
提前感谢您的任何建议。
【问题讨论】:
-
您需要打开本地网络服务器才能查看 html,因为它正在请求获取 json。
-
我打开了本地网络服务器并让 localhost 正常工作,但仍然无法生成地图。