defaultBasePage = c('',
'',
'
',
' ',
' YYYY',
' ',
' ',
' ',
' ',
' WWHH',
' ',
'')
# lat - the vector of latitudes
# long - the vector of longitudes
# desc - the vector of descriptions
# outFileName - the output file name
# title - the title of the html page
# zoom - the zoom on the map
# windowWidth - the width of the map
# windowHeight - the height of the map
# markerIcons - the png files to use to mark points
# markerIconWidth - the width of the marked points
# markerIconHeight - the height of the marked points
# pageBase - the skeleton html code (maybe this should be a local variable)
CreateGoogleMap = function( lat, long, desc, outFileName, title='',
zoom=13, windowWidth=1200, windowHeight=550, markerIcons=NA,
markerIconWidth=7, markerIconHeight=7, pageBase=defaultBasePage )
{
f = file(outFileName, "w")
tl = grep('YYYY', pageBase)
for (i in 1:(tl-1))
{
cat( pageBase[i], sep="\n", file=f )
}
cat( paste('\t', title, '\n' ), file=f )
rln = grep('XXXX', pageBase)
for (i in (tl+1):(rln-1))
{
cat( pageBase[i], sep="\n", file=f )
}
cat(paste('\t\tmap.setCenter(new GLatLng('
, mean(lat),',', mean(long),'),', zoom, ');', sep=''),
sep='\n', file=f)
# Now add the markers.
for (i in 1:(length(lat)))
{
cat(paste('\t\tvar point = new GLatLng(',
lat[i], ',', long[i], ');\n', sep=''), file=f)
if (sum(is.na(markerIcons))==0)
{
cat(paste('\t\tvar icon = new GIcon();\n', sep=''),
file=f)
cat(paste('\t\ticon.image = \"', markerIcons[i],'\";\n', sep=''),
file=f)
cat(paste('\t\ticon.iconSize = new GSize(', markerIconWidth,
',', markerIconHeight, ');\n', sep=''), file=f)
cat(paste('\t\ticon.iconAnchor = new GPoint(',
round(markerIconWidth/2), ',',
round(markerIconHeight/2), ');\n', sep=''), file=f)
cat(paste('\t\ticon.infoWindowAnchor = new GPoint(',
round(markerIconWidth/2), ',',
round(markerIconHeight/2), ');\n', sep=''), file=f)
cat(paste('\t\tmap.addOverlay(createMarker(point', ',\"',
desc[i], '\", icon));\n', sep=''), file=f)
}
else
{
cat(paste('\t\tmap.addOverlay(createMarker(point', ',\"',
desc[i], '\"));\n', sep=''), file=f)
}
}
whl = grep('WWHH', pageBase)
for (i in (rln+1):whl-1)
{
cat( pageBase[i], sep="\n", file=f )
}
cat(paste('\t', sep=''), file=f)
for (i in (whl+1):length(pageBase))
{
cat( pageBase[i], sep="\n", file=f )
}
close(f)
}