googleMapsDoc: Create an HTML document displaying a Google Map

Description Usage Arguments Value References See Also Examples

Description

This is the high-level function for creating a document that can be displayed in a Web browser to show a Google Map. This allows us to display geographical data on a Google Map that is interactive. We can add many overlay objects such as lines, paths and polygons and interactive markers.

In the future, we will be able to add images. We can also control different aspects of interaction.

Usage

1
2
3
4
5
6
7
8
googleMapsDoc(code, center = c(0, 0), zoom = 1, file = NA,
               scripts = character(), title = character(),
                dims = c(750, 750), control = "GSmallZoomControl3D",
                mapOpts = NULL,
                key = getOption("GoogleMapsKey"), version = 3,
                 onload = "initialize()", canvas.id = "map_canvas",
                  template = system.file("templates", "template.html",
                                           package = "R2GoogleMaps"))

Arguments

code

a character string/vector that specifies the essential code for the function that creates the Google Map within the document. Typically, this code is appended to generic code that creates the map, centers it at the coordinates specified via center and optionally adds a control. If this has the class AsIs (e.g. using the I function), it is treated as self-contained.

center

a numeric vector giving the latitude and longitude at which the map should be centered

zoom

an integer giving the zoom level for when the map is first displayed. This should be between 1 and 20 inclusive. See the Google Maps API.

file

a character string giving the name of the file that is to be created. If this is NA or an empty character vector (character()), the HTML document is returned (as an HTMLInternalDocument object). One can then modify this and add more content to it and then save it, or perhaps send it to a browser using, e.g. DCOM or AppleScript or a shell call.

scripts

a character vector giving either the names of JavaScript code files or the JavaScript code itself which are inserted into the HTML document. If these are file names, a reference to that file will be added. In the future, we will provide a mechanism that allows the caller of this function to control whether a reference is used or the contents of the files are added.

title

a string that is used for the title of the HTML document, appearing in the window frame

dims

a numeric/integer vector giving the number of pixels in the horizontal and vertical orientations for the map canvas on which the map is drawn and displayed. One can specify an individual value but it must be a named vector, using either width or height.

control

a character vector giving the name of the type of GControl to display on the map. This can be a partial match (see pmatch) to the class name from the Google Maps API. If no control is to appear, use the empty string - "".

mapOpts

a named list providing named options that map to a GMapOptions constructor/initializer. This can be used to specify the mapTypes, the size, the background color, ...

key

a character string giving the Google Maps API key to use when connecting to the Google Maps server. See registering an application in the Google Maps documentation.

version

an integer specifying the version of the Google Maps API to use. This currently should be either 2 or 3.

onload

the JavaScript call that is used to create the map when the document is loaded. This is used as the value of the onload attribute of the HTML document's body element.

canvas.id

the name of the HTML element that is used to display the map. This is typically not specified, but if the HTML document is to have two or more maps displayed, one may want to control this.

template

the name of the file that contains the HTML code that acts as a template.

Value

If file is a string, this is returned and the corresponding file is created/overwritten with the generated HTML document. Alternatively, if file is NA or an empty vector, the generated HTML document is returned as an HTMLInternalDocument object.

References

http://code.google.com/apis/maps/documentation/reference.html and http://code.google.com/apis/maps/documentation/index.html

See Also

http://www.omegahat.org/R2GoogleMaps/sampleDocs/sfcabs.html

gpolyline, gmarker

Examples

1
2
3
4
5
6
7
 # Thanks to Markus Loecher's example.
plottingCode = "// ..."  # need to put something of substance
googleMapsDoc(c("map.setUIToDefault();",
                "map.enableGoogleBar();",
                "map.addControl(new GSmallZoomControl3D());",
                plottingCode
               ), mapOpts = list(googleBarOptions = c(style = "new")))

duncantl/R2GoogleMaps documentation built on May 15, 2019, 5:26 p.m.