ggooglemaps: Google maps widget

Description Usage Arguments Details Value Methods Note Examples

View source: R/ggooglemaps.R

Description

Google maps widget

The GGoogleMaps class provides the methods for the googlemaps widget. As the API for google maps far exceeds the primitive API of gWidgets, reference class methods are used to expose the google maps API. See the example for illustrations.

Add a marker to the map

The GGoogleMapsMarker class provides a class for marker objects on a map. The main argument is add_handler_clicked, which allows one to assign a callback when a marker is clicked.

Usage

1
2
3
4
ggooglemaps(center = c(45, 45), zoom = 13, maptype = "roadmap", container,
  ..., width = NULL, height = 400, ext.args = NULL)

ggooglemaps_marker(position, title = NULL, icon = NULL, map)

Arguments

center

lat/lng pair where map should be centered

zoom

zoom level for initial map

maptype

Type of map

container

A parent container. In gWidgetsWWW2 a parent container is not optional (though it can be substituted with the parent argument in some circumstances). The parent specifies the widget heirarchy and the ... argument is used to pass along arguments to layout the child component in the parent container. Typically, these are passed to the add method of the parent container.

...

Used to pass along argument to the parent container's add method and possible other arguments to the underlying ference class constructors.

width

width in pixels of component. Sizing in gWidgetsWWW2 is sometimes necessary as the arguments expand and fill are not well implemented.

height

height in pixels of the component.

ext.args

The contructors of gWidgetsWWW2 ultimately call an Ext constructor. The options passed to the Ext constructor may be added to or overridden by use of this argument. Values are passed in as named list components and with values converted into JavaScript objects by asJSObject.

position

lat/lng pair for position of mark

title

optional tooltip text

icon

option icon, stock name or url

map

ggooglemaps instance

Details

Widget to display a google map and expose some of the google maps API through R methods

Value

a GGoogleMaps object

a GGoogleMapsObject

Methods

add_bikelayer(value = TRUE)

Add (or remove) a bicycle layer

add_markers(markers)

Markers coerced to a JavaScript array. It can be a) a matrix or data frame with latlong pairs, with lat being first column, b) a character vector or data frame (first column) of strings to call geoCodeAddr. The optional column 'marker' holds text for the marker to display. Additional columns for setCenter and listeneres are possible, but not yet implemented

add_R_callback(signal, ...)

Add a callback into for the Ext signal. Return callback idas a list.

add_trafficlayer(value = TRUE)

Add (or remove) a traffic layer

call_method(meth, ...)

Call method of map. Change arguments into object through coerceToJSString

create_info_window(inwin, point, marker)

Create Info Window, inwin: infowindow content, point: lat/lng pair, marker: title of marker

get_map()

Return jS call to get google map. No trailing ; here

set_center(center)

Center map on center, a lat long pair

set_size(val)

Set size, specified as width or c(width, height) or list(width,height)

set_zoom(zoom)

Set zoom level for map

Note

The bulk of the functionality is provided through reference class methods.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
w <- gwindow("hello", renderTo="replaceme")
sb <- gstatusbar("Powered by gWidgetsWWW and Rook", cont=w)

## Show map of central park
central_park <- c(40.782686, -74.01) ## central park

## make map
gm <- ggooglemaps(cont=w, center=central_park, zoom=12, height=400)

## Show how to click to add a polygon
g1 <- ggroup(cont=w)
glabel("Click some points, then click button to: ", cont=g1)
x <- numeric(0); y <- numeric(0)
b <- gbutton("add polygon", cont=g1, handler=function(h,...) {
  ggooglemaps_polygon(cbind(x, y), stroke=list(color="#FF00FF"), fill=list(color="#00FF00"), map=gm)
})
addHandlerClicked(gm, handler=function(h,...) {
  ggooglemaps_marker(position=c(h$lat, h$lng), title="", map=gm)
  x <<- c(x, h$lat); y <<- c(y, h$lng)
})
## How to add a marker with a callback to open an info window
m <- ggooglemaps_marker(position=central_park, title="click me", map=gm)
addHandlerClicked(m, handler=function(h,...) {
  ggooglemaps_infowindow(h$obj, content = "Hello world", map=gm)
})


## Buttons to toggle traffic and bicycle overlays
g1 <- ggroup(cont=w)
glabel("Change map type", cont=g1)
gcombobox(c("roadmap", "satellite", "hybrid", "terrain"), cont=g1, handler=function(h,...) {
  gm$set_maptype(svalue(h$obj, index=FALSE))
})
gcheckbox("Traffic overlay", checked=FALSE, width=150, cont=g1, handler=function(h,...) {
  gm$add_trafficlayer(svalue(h$obj))
})
gcheckbox("Bicycle overlay", checked=FALSE, width=150, cont=g1, handler=function(h,...) {
  gm$add_bikelayer(svalue(h$obj))
})

jverzani/gWidgetsWWW2 documentation built on May 18, 2017, 2 p.m.