2

我要做什么: 我正在尝试在漂亮的交互式地图上绘制 2 组具有不同图标的点(容器)。(船只有经度和纬度)交互性很重要!

代码实际上会进入闪亮应用程序的 iframe 中。

我设置了一个示例容器数据集(两组 5 个),并将它们绘制到 2 个单独的层上。我一直在做一些研究,plotGoogleMaps 似乎是一个不错的选择。

library(plotGoogleMaps)
vessels = data.frame(id = c(1:10)
                     , lat = c(22.0959, 22.5684, 21.9189, 21.8409, 22.4663, 22.7434, 22.1658, 24.5691, 22.4787, 22.3039)
                     , lon = c(114.021, 114.252, 113.210, 113.128, 113.894, 114.613, 113.803, 119.730, 113.910, 114.147))
group1 = vessels[1:5,]
group2 = vessels[6:10,]

coordinates(group1) = ~ lon + lat
proj4string(group1) = CRS("+proj=longlat +datum=WGS84")
group1 <- SpatialPointsDataFrame( group1 , data = data.frame( ID = row.names( group1 ) ))

coordinates(group2) = ~ lon + lat
proj4string(group2) = CRS("+proj=longlat +datum=WGS84")
group2 <- SpatialPointsDataFrame( group2 , data = data.frame( ID = row.names( group1 ) ))


m <- plotGoogleMaps(group1, legend = FALSE, layerName = "Vessels 1"
                    , add = T, iconMarker='http://maps.google.com/mapfiles/kml/shapes/placemark_circle.png', mapTypeId='ROADMAP')
m <- plotGoogleMaps(group2,legend = FALSE, layerName = "Vessels 2"
                    , previousMap = m , add = F
                    , iconMarker = 'http://maps.google.com/mapfiles/kml/shapes/placemark_circle.png'
                    , filename = "out.htm")

谁能告诉我代码哪里出错了?任何建设性的想法也受到赞赏!

结果:

在此处输入图像描述

图标标记实际上并未被拾取,您可以在结果中看到它。我想使用自定义图像。感谢您的帮助

4

1 回答 1

4

您需要对最后两行代码进行一些修改,然后您将得到您想要的。

m <- plotGoogleMaps(group1, legend = FALSE, layerName = "Vessels 1"
                , add =T,
iconMarker=rep('http://maps.google.com/mapfiles/kml/shapes/placemark_circle.png',nrow(group1) ), 
mapTypeId='ROADMAP', filename = "out.htm")

m <- plotGoogleMaps(group2,legend = FALSE, layerName = "Vessels 2"
                , previousMap = m , add = F
                , iconMarker = rep('http://maps.google.com/mapfiles/kml/shapes/placemark_circle.png',nrow(group2) )
                , filename = "out.htm")

在此处输入图像描述

于 2015-05-12T05:44:00.467 回答