ol_map2Strings: OpenLayers Map HTML to List

View source: R/write_functions.R

ol_map2StringsR Documentation

OpenLayers Map HTML to List

Description

Assigns Ol.Map HTML content to list.

Usage

ol_map2Strings(ol.map.obj, width = NULL, height = NULL,
  ol.source.url = NULL, nga.olsource = FALSE, map.heading = NULL,
  map.note = NULL)

Arguments

ol.map.obj

Ol.Map object to be exported.

width

numeric or character CSS value width of map container.

height

numeric or character CSS value height of map container.

ol.source.url

character string containing the url to the OpenLayers javascript library. Ignored if nga.olsource is TRUE.

nga.olsource

logical. TRUE will use the OpenLayers 3.16.0 javascript library from https://home.gvs.nga.mil (requires authentication); FALSE uses the sources the ol.source.url, if provided, or embeds the OpenLayers 3.21.1 JavaScript code in the HTML head. Only used if ol.source.url is missing or NULL.

map.heading

character heading to be placed over map in html h1 tag.

map.note

character note placed in html paragraph (<p>) tag centered under map container.

Details

Ol.Map object HTML is exported to a list object that can be deployed in a variety of applications or server environments. See exmaples for a minimal example using RShiny. This method does not currently support adding multiple maps to the same web page, as javascript variable names would be replicated.

Value

list object with the following character elements:

$head.meta.IE.compatibility HTML meta tag for IE compatability viewing.
$head.script HTML script block including or sourcing the OpenLayers Javascript library (see ol.map.obj).
$style CSS code for styling the map and legends.
$body.html HTML map and legend containers, and associated elements.
$body.script Javascript code writing the layer and map objects.

See Also

ol_map, ol_map2HTML,

Examples

heatmap.pts <- matrix(
    c(
        rnorm(100,-80.385,1), #Miami Longitudes
        rnorm(100,-117.1611,3), #San Diego Longitudes
        rnorm(100,25.782618,1), #Miami Latitudes
        rnorm(100,32.7157,3) # San Diego Latitudes
    ),ncol=2
)
mymap <- ol_map(
    center=c(-98.5,28.5),
    zoom=4
 ) + 
    streetmap() +
    ol_geom_heatmap(
        heatmap.pts,
        name="Random Heatmap",
        toggle.control=TRUE,
        opacity=0.25
        )
## The following line will create image files
## as needed for point layers and legends.
## None are required in this example.
HTML.strings <- ol_map2Strings(
  mymap,
  nga.olsource=FALSE,
  map.note="Heatmap of random points centered on Miami and San Diego."
)
## Minimal shiny example
## Not run: 
library(shiny)
ui <- shinyUI(
    fluidPage(
        #Add OpenLayers Javascript source & CSS to head
        tags$head(
            HTML(HTML.strings[[1]])
            HTML(HTML.strings[[2]]),
            tags$style(HTML(HTML.strings[[3]]))
        ),
        titlePanel("Random Heatmap"),
        mainPanel(
            tags$div(HTML(HTML.strings[[4]]))
        ),
        tags$script(HTML(HTML.strings[[5]]))
    )
)
server <- function(input,output){
}
shinyApp(ui=ui,server)

## End(Not run)

cemarks/ROpenLayers documentation built on March 31, 2022, 12:05 p.m.