is there a way to design a map with plotGoogleMaps having a legend that controls layers of the same variable?
Using meuse dataset from gstat package as an example, the goal would be to obtain a thickbox for each type of landuse. Therefore, letting the user decide which layer to look at, either one by one, or a selection of several or all of them:
# Data Preparation
library(sp)
data(meuse)
coordinates(meuse)<-~x+y
proj4string(meuse) <- CRS('+init=epsg:28992')
ic=iconlabels(meuse$landuse, height=12)
m<-plotGoogleMaps(meuse,zcol='landuse',filename='Map.htm', iconMarker=ic)
The best solution would be a command to make a breakdown by values of a variable...
Or alternatively, do we need to create a map for each layer (all 15 of them) and then adding them together? Would it be a more convenient way to acheive this? I got a project with more than 300 layers...
#Alternative the long way : Example with 3 landuse values
data(meuse)
list <- list(unique(meuse$landuse)) #list all 15 landuse values
Ah <- subset(meuse, landuse == "Ah")
coordinates(Ah)<-~x+y
proj4string(Ah) <- CRS('+init=epsg:28992')
ic=iconlabels(Ah$landuse, height=12)
m.Ah<-plotGoogleMaps(Ah,zcol='landuse', legend=FALSE, filename='MapAh.htm', iconMarker=ic, add=TRUE)
Fw <- subset(meuse, landuse == "Fw")
coordinates(Fw)<-~x+y
proj4string(Fw) <- CRS('+init=epsg:28992')
icf=iconlabels(Fw$landuse, height=12)
m.Fw<-plotGoogleMaps(Fw,zcol='landuse',legend=FALSE, filename='MapFw.htm', iconMarker=icf, previousMap=m.Ah, add=TRUE)
W <- subset(meuse, landuse == "W")
coordinates(W)<-~x+y
proj4string(W) <- CRS('+init=epsg:28992')
icw=iconlabels(W$landuse, height=12)
m.W<-plotGoogleMaps(W,zcol='landuse', legend=TRUE, filename='MapFw.htm', iconMarker=icw,previousMap=m.Fw)
The second best solution would be to loop this all.