当我尝试安装名为“leaflet”的软件包时,CRAN对话框只显示一个名为
leafletR
的软件包。安装并加载该软件包会在控制台上显示一条消息,表示安装成功:
Your leaflet map has been saved under /Users/myuser_name/map/map.html
那张地图具有所需的功能。考虑到我可以从Web浏览器访问的信息量,我猜测我实际上是通过Chrome与OpenStreetMap服务器进行接口交互,而不是与磁盘文件数据服务交互。
从CRAN下载的版本中没有addTiles函数。使用sos::findFn在任何其他软件包中都找不到它。这可能是仅在github版本中才有的新功能:
https://github.com/chgrl/leafletR
进一步搜索显示,这仅托管在RStudio上,而不是在CRAN上:
http://robinlovelace.net/r/2015/02/01/leaflet-r-package.html
我需要一个新的会话,因为我怀疑leafle和leafletR同时加载导致错误。在浏览器中,我左键单击以打开ViewSource窗口,然后选择并复制以下内容。Chrome和Firefox都能够显示底层代码,并支持选择和复制到编辑器。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<script src="lib/htmlwidgets-0.3.2/htmlwidgets.js"></script>
<script src="lib/jquery-1.11.1/jquery.min.js"></script>
<link href="lib/leaflet-0.7.3/leaflet.css" rel="stylesheet" />
<script src="lib/leaflet-0.7.3/leaflet.js"></script>
<link href="lib/leafletfix-1.0.0/leafletfix.css" rel="stylesheet" />
<script src="lib/leaflet-binding-0.0.16/leaflet.js"></script>
</head>
<body style="background-color:white;">
<div id="htmlwidget_container">
<div id="htmlwidget-3689" style="width:100%;height:400px;" class="leaflet"></div>
</div>
<script type="application/json" data-for="htmlwidget-3689">{ "x": {
"calls": [
{
"method": "addTiles",
"args": [
"http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
null,
{
"minZoom": 0,
"maxZoom": 18,
"maxNativeZoom": null,
"tileSize": 256,
"subdomains": "abc",
"errorTileUrl": "",
"tms": false,
"continuousWorld": false,
"noWrap": false,
"zoomOffset": 0,
"zoomReverse": false,
"opacity": 1,
"zIndex": null,
"unloadInvisibleTiles": null,
"updateWhenIdle": null,
"detectRetina": false,
"reuseTiles": false,
"attribution": "© <a href=\"http://openstreetmap.org\">OpenStreetMap</a> contributors, <a href=\"http://creativecommons.org/licenses/by-sa/2.0/\">CC-BY-SA</a>"
}
]
}
]
},"evals": [ ] }</script>
<script type="application/htmlwidget-sizing" data-for="htmlwidget-3689">{ "viewer": {
"width": "100%",
"height": 400,
"padding": 0,
"fill": true
},"browser": {
"width": "100%",
"height": 400,
"padding": 0,
"fill": true
} }</script>
</body>
</html>
代码本身并不足够。其余所需的支持文件将保存在与HTML文件同名的目录中,最好使用浏览器的“另存为...”功能。
![enter image description here](https://istack.dev59.com/1ZSuI.webp)