如何让image iconMarker适用于plotGoogleMaps R? [英] How to get image iconMarker working for plotGoogleMaps R?

查看:89
本文介绍了如何让image iconMarker适用于plotGoogleMaps R?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

What am I trying to do: I am trying to plot 2 groups of points (vessels) with different icons on a nice interactive map. (The vessels have longitude and latitude) The interactivity is important!

该代码实际上将放入闪亮的应用程序的iframe中.

The code will actually go inside an iframe in a shiny application.

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

I set up an example vessel data set (two groups of 5), and plot them onto 2 separate layers. I have been doing a bit of research and plotGoogleMaps seemed like a good package to go to.

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")

任何人都可以告诉我代码在哪里出问题了吗?任何建设性的想法也将受到赞赏!

Could anyone please tell me where the code is going wrong? Any constructive ideas are appreciated as well!

结果:

实际上并没有拾取图标标记,因为您可以在结果中看到它.我想使用自定义图片.谢谢您的帮助

The icon marker has not actually been picked up as you can see it on the result. I would like to use a custom image. Thank you for your help

推荐答案

您需要对最后两行代码进行一些修改,然后您将获得所需的内容.

You need a little modification on the last 2 lines of code, and than you will get what you want.

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")

这篇关于如何让image iconMarker适用于plotGoogleMaps R?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆