ROpenLayers | R Documentation |
ROpenLayers leverages the power of OpenLayers javascript libraries and web-based Mapservers to enable informative visualization.
The purpose of this package is to make it easy for a user to visualize
geo-spatial data and analyses using the open source
OpenLayers javascript library and
online map servers. The process for creating a visualization
imitates the process of creating a plot in R package
ggplot2
.
First, an OpenLayers Map object is created with a
call to the ol_map
method.
Next, layers and scales are created and added. Layers can reference map servers to provide underlying base maps or vector features (polygons, lines, or points) created or imported in R. These capabilities are described in the following sections.
Finally, the updated map object is exported to HTML/javascript for
viewing in a browser, hosting on a server, or embedding into another
application or format. Export methods are ol_map2HTML
and
ol_map2Strings
.
OpenLayers
is an open source javascript library that makes it easy to put a
dynamic map on any web page. It is licensed under the 2-clause BSD
license (see OpenLayers Licence).
This license will appear commented within OpenLayers CSS code in the
HTML exports created by this package. However, this package does not
contain any of the OpenLayers javascript source code; rather, it exports
HTML code that source these libraries when loaded. Therefore, these
products will not render without network access to the OpenLayers
javascript library. By default, the products exported by this package
source OpenLayers 3.16.0, but the user has the option to set the
source URL (see ol_map
).
ESRI ArcGIS hosts several
publicly available map servers at
arcgisonline.com,
which can accessed via REST APIs and rendered using OpenLayers javascript methods.
A subset of these are made available in this package through the
public_arcgis_basemap
method. Alternatively, a user can
specify any ArcGIS map server using the user_arcgis_basemap
method. Note that while these maps servers are publicly available, they are
not necessarily open-licensed. Users must ensure they comply with each
map server's license and terms of use.
OpenStreetMap also hosts a public and
open license map server that can be imported as a layer using OpenLayers.
See public_OSM_basemap
.
As stated above, the user_arcgis_basemap
method allows the user
to manually specify any available ArcGIS map server. This package also provides
access to US National Geospatial-Intelligence Agency servers hosted
at NGA.mil through the nga_basemap
method. Note that these servers require authentication, which will be requested
at the time of access (i.e., when the HTML page is opened in a browser).
This package enables users to rapidly access and write OpenLayers vector layers in javascript. The following methods enable that functionality.
ol_geom_polygon
ol_geom_line
ol_geom_point
ol_geom_icon
ol_geom_circle
ol_geom_heatmap
ol_geom_text
New in version 1.0.0–geocode addresses using ArcGIS
geocoding service. See geocode
.
data(quakes) center <- c(mean(quakes$long),mean(quakes$lat)) quakes$long[which(quakes$long>180)]<-quakes$long[which(quakes$long>180)]-360 tooltips <- paste("Depth",quakes$depth,sep=": ") mymap <- ol_map( zoom = 5, center = center ) basemap.layer <- oceanbase() point.layer <- ol_geom_point( quakes[,c("long","lat")], mapping = ol_aes(fill=mag), df = quakes, name = "Earthquake Points", toggle.control=TRUE, tooltip = tooltips ) heatmap.layer <- ol_geom_heatmap( quakes[,c("long","lat")], name = "Earthquake Heatmap", toggle.control=TRUE, weight.values = quakes$mag, opacity = 0.25 ) mymap <- mymap + basemap.layer + point.layer + ol_scale_fill_continuous(name="Magnitude",display=TRUE) + heatmap.layer ## Not run: # Save to file and open in browser ol_map2HTML( mymap, "Quakes.html", map.heading = "Earthquake Data Visualization" ) browseURL("Quakes.html") ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.