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!

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

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!

Result:

enter image description here

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

Gregor Thomas
  • 136,190
  • 20
  • 167
  • 294
Peter
  • 284
  • 2
  • 9
  • I ran your code in a fresh R session, and I got a plot with some points on it. I think you need to tell us where the results are going wrong. What do you expect, and what do you get? I get something that looks plausibly like what you might want. – Gregor Thomas May 08 '15 at 22:50
  • I would have attached a picture (but lack of reputation does not allow it). I am getting the default icon markers (with numbers on them). Instead of the ones I referenced in the code: http://maps.google.com/mapfiles/kml/shapes/placemark_circle.png – Peter May 08 '15 at 23:11
  • Oh, that makes sense. You should probably edit that into your question explicitly. Also feel free to upload something to imgur, someone with more rep can edit it into your question. – Gregor Thomas May 08 '15 at 23:12

1 Answers1

4

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

enter image description here