diff --git a/.lintr b/.lintr new file mode 100644 index 0000000..47206f6 --- /dev/null +++ b/.lintr @@ -0,0 +1,6 @@ +linters: with_defaults( + camel_case_linter = NULL, # 122 + line_length_linter = NULL, # 33 + commented_code_linter = NULL, # 3 + NULL + ) diff --git a/R/basemapLayers.R b/R/basemapLayers.R index 36f64e2..5b495fe 100644 --- a/R/basemapLayers.R +++ b/R/basemapLayers.R @@ -4,28 +4,28 @@ #' Taken from \url{https://esri.github.io/esri-leaflet/api-reference/layers/basemap-layer.html}. #' @export esriBasemapLayers <- list( - 'Streets' = 'Streets', - 'Topographic' = 'Topographic', - 'NationalGeographic' = 'NationalGeographic', - 'Oceans' = 'Oceans', - 'Gray' = 'Gray', - 'DarkGray' = 'DarkGray', - 'Imagery' = 'Imagery', - 'ShadedRelief' = 'ShadedRelief', - 'Terrain' = 'Terrain') + "Streets" = "Streets", + "Topographic" = "Topographic", + "NationalGeographic" = "NationalGeographic", + "Oceans" = "Oceans", + "Gray" = "Gray", + "DarkGray" = "DarkGray", + "Imagery" = "Imagery", + "ShadedRelief" = "ShadedRelief", + "Terrain" = "Terrain") #' Esri basemap labels. #' #' Taken from \url{https://esri.github.io/esri-leaflet/api-reference/layers/basemap-layer.html#optional-labels}. #' @export esriBasemapLabels <- list( - 'OceansLabels' = 'OceansLabels', - 'GrayLabels' = 'GrayLabels', - 'DarkGrayLabels' = 'DarkGrayLabels', - 'ImageryLabels' = 'ImageryLabels', - 'ImageryTransportation' = 'ImageryTransportation', - 'ShadedReliefLabels' = 'ShadedReliefLabels', - 'TerrainLabels' = 'TerrainLabels' + "OceansLabels" = "OceansLabels", + "GrayLabels" = "GrayLabels", + "DarkGrayLabels" = "DarkGrayLabels", + "ImageryLabels" = "ImageryLabels", + "ImageryTransportation" = "ImageryTransportation", + "ShadedReliefLabels" = "ShadedReliefLabels", + "TerrainLabels" = "TerrainLabels" ) #' Adds a ArcGIS Basemap layer @@ -37,7 +37,7 @@ esriBasemapLabels <- list( #' @param options Basemap Layer Options. You can pass \code{\link[leaflet]{tileOptions}()}. #' @examples \dontrun{ #' leaflet() %>% -#' addEsriBasemapLayer(esriBasemapLayers$Oceans, autoLabels=TRUE) +#' addEsriBasemapLayer(esriBasemapLayers$Oceans, autoLabels = TRUE) #' } #' @export addEsriBasemapLayer <- function( @@ -47,21 +47,21 @@ addEsriBasemapLayer <- function( map <- addEsriDependency(map) - if(is.null(options)) { + if (is.null(options)) { options <- list() } - if(!(key %in% esriBasemapLayers || key %in% esriBasemapLabels)) { + if (!(key %in% esriBasemapLayers || key %in% esriBasemapLabels)) { stop("Invalid Basemap layer Key") } labelLayer <- NULL - if(autoLabels) { - labelLayer <- esriBasemapLabels[[sprintf("%sLabels",key)]] + if (autoLabels) { + labelLayer <- esriBasemapLabels[[sprintf("%sLabels", key)]] } leaflet::invokeMethod( map, leaflet::getMapData(map), - 'addEsriBasemapLayer', key, labelLayer, layerId, group, options) + "addEsriBasemapLayer", key, labelLayer, layerId, group, options) } diff --git a/R/dynamicMapLayers.R b/R/dynamicMapLayers.R index 2f953a6..aabafb0 100644 --- a/R/dynamicMapLayers.R +++ b/R/dynamicMapLayers.R @@ -1,53 +1,53 @@ #' Options for dynamic map layer. #' -#' @param format Output format of the image. -#' @param transparent Allow the server to produce transparent images. -#' @param f Server response content type. -#' @param attribution Attribution from service metadata copyright text is automatically displayed in Leaflet's default control. This property can be used for customization. -#' @param layers An array of Layer IDs like [3,4,5] to show from the service. -#' @param layerDefs A string representing a query to run against the service before the image is rendered. This can be a string like "3:STATE_NAME='Kansas'" or an object mapping different queries to specific layers {3:"STATE_NAME='Kansas'", 2:"POP2007>25000"}. -#' @param opacity Opacity of the layer. Should be a value between 0 (completely transparent) and 1 (completely opaque). -#' @param position Position of the layer relative to other overlays. -#' @param maxZoom Closest zoom level the layer will be displayed on the map. -#' @param minZoom Furthest zoom level the layer will be displayed on the map. -#' @param dynamicLayers JSON object literal used to manipulate the layer symbology defined in the service itself. Requires a 10.1 (or above) map service which supports dynamicLayers requests. -#' @param token If you pass a token in your options it will be included in all requests to the service. -#' @param proxy URL of an \href{https://developers.arcgis.com/javascript/jshelp/ags_proxy.html}{ArcGIS API for JavaScript proxy} or \href{https://github.com/Esri/resource-proxy}{ArcGIS Resource Proxy} to use for proxying requests. -#' @param useCors If this service should use CORS when making GET requests. +#' @param format Output format of the image. +#' @param transparent Allow the server to produce transparent images. +#' @param f Server response content type. +#' @param attribution Attribution from service metadata copyright text is automatically displayed in Leaflet's default control. This property can be used for customization. +#' @param layers An array of Layer IDs like [3, 4, 5] to show from the service. +#' @param layerDefs A string representing a query to run against the service before the image is rendered. This can be a string like "3:STATE_NAME="Kansas"" or an object mapping different queries to specific layers {3:"STATE_NAME="Kansas"", 2:"POP2007>25000"}. +#' @param opacity Opacity of the layer. Should be a value between 0 (completely transparent) and 1 (completely opaque). +#' @param position Position of the layer relative to other overlays. +#' @param maxZoom Closest zoom level the layer will be displayed on the map. +#' @param minZoom Furthest zoom level the layer will be displayed on the map. +#' @param dynamicLayers JSON object literal used to manipulate the layer symbology defined in the service itself. Requires a 10.1 (or above) map service which supports dynamicLayers requests. +#' @param token If you pass a token in your options it will be included in all requests to the service. +#' @param proxy URL of an \href{https://developers.arcgis.com/javascript/jshelp/ags_proxy.html}{ArcGIS API for JavaScript proxy} or \href{https://github.com/Esri/resource-proxy}{ArcGIS Resource Proxy} to use for proxying requests. +#' @param useCors If this service should use CORS when making GET requests. #' @param ... extra options #' @export dynamicMapLayerOptions <- function( - format = 'png24', + format = "png24", transparent = TRUE, - f = 'json', - attribution = '', - layers = NULL, + f = "json", + attribution = "", + layers = NULL, layerDefs = NULL, opacity = 1, - position = 'front', + position = "front", maxZoom = NULL, minZoom = NULL, dynamicLayers = NULL, - token = NULL, - proxy = NULL, - useCors = TRUE, + token = NULL, + proxy = NULL, + useCors = TRUE, ... ) { leaflet::filterNULL(list( - format = format, + format = format, transparent = transparent, f = f, attribution = attribution, - layers = layers, + layers = layers, layerDefs = layerDefs, opacity = opacity, position = position, maxZoom = maxZoom, minZoom = minZoom, dynamicLayers = dynamicLayers, - token = token, - proxy = proxy, - useCors = useCors, + token = token, + proxy = proxy, + useCors = useCors, ... )) @@ -77,11 +77,11 @@ addEsriDynamicMapLayer <- function( popupFunction = NULL, popupOptions = NULL, layerId = NULL, group = NULL) { map <- addEsriDependency(map) - if(is.null(options)) { + if (is.null(options)) { options <- list() } leaflet::invokeMethod( map, leaflet::getMapData(map), - 'addEsriDynamicMapLayer', url, layerId, group, + "addEsriDynamicMapLayer", url, layerId, group, options, popupFunction, popupOptions) } diff --git a/R/featureLayers.R b/R/featureLayers.R index 289fcc8..b877a7b 100644 --- a/R/featureLayers.R +++ b/R/featureLayers.R @@ -1,30 +1,30 @@ #' Options for featureLayers. #' -#' @param where String An optional expression to filter features server side. -#' String values should be denoted using single quotes ie: where: "FIELDNAME = 'field value'"; More information about valid SQL syntax can be found at \url{http://resources.arcgis.com/en/help/main/10.2/index.html#/SQL_reference_for_query_expressions_used_in_ArcGIS/00s500000033000000/}. -#' @param minZoom Integer Minimum zoom level of the map that features will display. +#' @param where String An optional expression to filter features server side. +#' String values should be denoted using single quotes ie: where: "FIELDNAME = "field value""; More information about valid SQL syntax can be found at \url{http://resources.arcgis.com/en/help/main/10.2/index.html#/SQL_reference_for_query_expressions_used_in_ArcGIS/00s500000033000000/}. +#' @param minZoom Integer Minimum zoom level of the map that features will display. #' example: minZoom:0 -#' @param maxZoom Integer Maximum zoom level of the map that features will +#' @param maxZoom Integer Maximum zoom level of the map that features will #' example: maxZoom:19 -#' @param cacheLayers Boolean Will remove layers from the internal cache when they are removed from the map. -#' @param fields Array An array of fieldnames to pull from the service. -#' Includes all fields by default. You should always specify the name of the unique id for the service. Usually either 'FID' or 'OBJECTID'. -#' @param from Date When paired with to defines the time range of features to display. +#' @param cacheLayers Boolean Will remove layers from the internal cache when they are removed from the map. +#' @param fields Array An array of fieldnames to pull from the service. +#' Includes all fields by default. You should always specify the name of the unique id for the service. Usually either "FID" or "OBJECTID". +#' @param from Date When paired with to defines the time range of features to display. #' Requires the Feature Layer to be time enabled. -#' @param to Date When paired with from defines the time range of features to display. +#' @param to Date When paired with from defines the time range of features to display. #' Requires the Feature Layer to be time enabled. -#' @param timeField false The name of the field to lookup the time of the feature. -#' Can be an object like {start:'startTime', end:'endTime'} or a string like 'created'. -#' @param timeFilterMode 'server' (default) or 'client' Determines where features are filtered by time. -#' By default features will be filtered by the server. If set to 'client' all features are requested and filtered by the app before display. -#' @param simplifyFactor Integer How much to simplify polygons and polylines. +#' @param timeField false The name of the field to lookup the time of the feature. +#' Can be an object like {start:"startTime", end:"endTime"} or a string like "created". +#' @param timeFilterMode "server" (default) or "client" Determines where features are filtered by time. +#' By default features will be filtered by the server. If set to "client" all features are requested and filtered by the app before display. +#' @param simplifyFactor Integer How much to simplify polygons and polylines. #' More means better performance, and less means more accurate representation. -#' @param precision Integer How many digits of precision to request from the server. +#' @param precision Integer How many digits of precision to request from the server. #' Wikipedia has a great reference of digit precision to meters at \url{http://en.wikipedia.org/wiki/Decimal_degrees}. -#' @param token String If you pass a token in your options it will be included in all requests to the service. -#' @param proxy URL of an \href{https://developers.arcgis.com/javascript/jshelp/ags_proxy.html}{ArcGIS API for JavaScript proxy} or \href{https://github.com/Esri/resource-proxy}{ArcGIS Resource Proxy} to use for proxying requests. -#' @param useCors Boolean If this service should use CORS when making GET requests. -#' @param renderer L.svg or L.canvas The vector renderer to use to draw the service. +#' @param token String If you pass a token in your options it will be included in all requests to the service. +#' @param proxy URL of an \href{https://developers.arcgis.com/javascript/jshelp/ags_proxy.html}{ArcGIS API for JavaScript proxy} or \href{https://github.com/Esri/resource-proxy}{ArcGIS Resource Proxy} to use for proxying requests. +#' @param useCors Boolean If this service should use CORS when making GET requests. +#' @param renderer L.svg or L.canvas The vector renderer to use to draw the service. #' Usually L.svg but setting to L.canvas contains performance benefits for large polygon layers. #' @param ... extra options #' @export @@ -78,7 +78,7 @@ featureLayerOptions <- function( #' @param layerId A unique ID for the layer. #' @param group The name of the group this layer should be added to. #' the same parameter under \code{\link{addTiles}}) -#' @param markerType The type of marker. either 'marker' or 'circleMarker' +#' @param markerType The type of marker. either "marker" or "circleMarker" #' @param markerIcons Icons for Marker. #' @param markerIconProperty The property of the feature to use for marker icon. #' Can be a JS function which accepts a feature and returns an index of \code{markerIcons}. @@ -146,7 +146,7 @@ addEsriFeatureLayer <- function( map$dependencies <- c(map$dependencies, leaflet.extras::leafletExtrasDependencies$omnivore()) - if(useServiceSymbology) { + if (useServiceSymbology) { map <- addEsriRenderersDependency(map) } else { map <- addEsriDependency(map) @@ -157,33 +157,33 @@ addEsriFeatureLayer <- function( map <- addEsriClusterDependency(map) } - pathOptions = c(pathOptions, list( + pathOptions <- c(pathOptions, list( stroke = stroke, color = color, weight = weight, opacity = opacity, fill = fill, fillColor = fillColor, fillOpacity = fillOpacity, dashArray = dashArray, smoothFactor = smoothFactor, noClip = noClip)) markerIconFunction <- NULL - if(!is.null(markerIcons)) { - if(inherits(markerIcons,'leaflet_icon_set') || - inherits(markerIcons, 'leaflet_icon')) { + if (!is.null(markerIcons)) { + if (inherits(markerIcons, "leaflet_icon_set") || + inherits(markerIcons, "leaflet_icon")) { markerIconFunction <- defIconFunction - } else if(inherits(markerIcons,'leaflet_awesome_icon_set') || - inherits(markerIcons, 'leaflet_awesome_icon')) { - if(inherits(markerIcons,'leaflet_awesome_icon_set')) { - libs <- unique(sapply(markerIcons,function(icon) icon$library)) - map <- leaflet.extras::addAwesomeMarkersDependencies(map,libs) + } else if (inherits(markerIcons, "leaflet_awesome_icon_set") || + inherits(markerIcons, "leaflet_awesome_icon")) { + if (inherits(markerIcons, "leaflet_awesome_icon_set")) { + libs <- unique(sapply(markerIcons, function(icon) icon$library)) + map <- leaflet.extras::addAwesomeMarkersDependencies(map, libs) } else { map <- leaflet.extras::addAwesomeMarkersDependencies( - map,markerIcons$library) + map, markerIcons$library) } markerIconFunction <- awesomeIconFunction } else { - stop('markerIcons should be created using either leaflet::iconList() or leaflet::awesomeIconList()') + stop("markerIcons should be created using either leaflet::iconList() or leaflet::awesomeIconList()") } } leaflet::invokeMethod( - map, leaflet::getMapData(map), 'addEsriFeatureLayer', url, options, layerId, group, + map, leaflet::getMapData(map), "addEsriFeatureLayer", url, options, layerId, group, markerType, markerIcons, markerIconProperty, markerOptions, markerIconFunction, clusterOptions, clusterId, @@ -217,5 +217,5 @@ addEsriHeatmapFeatureLayer <- function( ))) leaflet::invokeMethod( map, leaflet::getMapData(map), - 'addEsriHeatmapFeatureLayer', url, layerId, group, options) + "addEsriHeatmapFeatureLayer", url, layerId, group, options) } diff --git a/R/htmlDependencies.R b/R/htmlDependencies.R index 56c382c..727495b 100644 --- a/R/htmlDependencies.R +++ b/R/htmlDependencies.R @@ -1,7 +1,7 @@ esriDependency <- function() { list( htmltools::htmlDependency( - "esri.leaflet",version = "1.0.4", + "esri.leaflet", version = "1.0.4", system.file("htmlwidgets/lib/esri", package = "leaflet.esri"), script = c("esri-leaflet.js", "esri-leaflet-bindings.js") ) @@ -20,7 +20,7 @@ addEsriDependency <- function(map) { esriClusterDependency <- function() { list( htmltools::htmlDependency( - "esri.leaflet.cluster",version = "1.0.2", + "esri.leaflet.cluster", version = "1.0.2", system.file("htmlwidgets/lib/esri-cluster", package = "leaflet.esri"), script = c("esri-leaflet-clustered-feature-layer-src.js") ) @@ -41,7 +41,7 @@ addEsriClusterDependency <- function(map) { esriGeocoderDependency <- function() { list( htmltools::htmlDependency( - "esri.leaflet.geocoder",version = "1.0.2", + "esri.leaflet.geocoder", version = "1.0.2", system.file("htmlwidgets/lib/esri-geocoder", package = "leaflet.esri"), script = c("esri-leaflet-geocoder.js"), stylesheet = c("esri-leaflet-geocoder.css") @@ -62,7 +62,7 @@ addEsriGeocoderDependency <- function(map) { esriHeatmapDependency <- function() { list( htmltools::htmlDependency( - "esri.leaflet.heatmap",version = "1.0.2", + "esri.leaflet.heatmap", version = "1.0.2", system.file("htmlwidgets/lib/esri-heatmap", package = "leaflet.esri"), script = c("leaflet-heat.js", "esri-leaflet-heatmap-feature-layer.js") @@ -83,7 +83,7 @@ addEsriHeatmapDependency <- function(map) { esriRenderersDependency <- function() { list( htmltools::htmlDependency( - "esri.leaflet.renderers",version = "1.0.2", + "esri.leaflet.renderers", version = "1.0.2", system.file("htmlwidgets/lib/esri-renderers", package = "leaflet.esri"), script = c("esri-leaflet-renderers.js") ) diff --git a/R/iconFunctions.R b/R/iconFunctions.R index 6af5b86..30d7f1d 100644 --- a/R/iconFunctions.R +++ b/R/iconFunctions.R @@ -1,6 +1,6 @@ defIconFunction <- JS("function(icon){ - if(!$.isEmptyObject(icon)) { + if (!$.isEmptyObject(icon)) { return L.icon(icon); } else { return L.icon(); @@ -9,8 +9,8 @@ defIconFunction <- awesomeIconFunction <- JS("function(icon){ - if(!$.isEmptyObject(icon)) { - if(!icon.prefix) { + if (!$.isEmptyObject(icon)) { + if (!icon.prefix) { icon.prefix = icon.library; } return L.AwesomeMarkers.icon(icon); diff --git a/R/imageMapLayers.R b/R/imageMapLayers.R index 8b72139..2c23208 100644 --- a/R/imageMapLayers.R +++ b/R/imageMapLayers.R @@ -1,46 +1,46 @@ #' Options for image map layer. #' -#' @param format Output format of the image. -#' @param f Server response content type. -#' @param opacity Opacity of the layer. Should be a value between 0 and 1. -#' @param position Position of the layer relative to other overlays. -#' @param maxZoom Closest zoom level the layer will be displayed on the map. -#' @param minZoom Furthest zoom level the layer will be displayed on the map. -#' @param from Date When paired with to defines the time range of data to display. +#' @param format Output format of the image. +#' @param f Server response content type. +#' @param opacity Opacity of the layer. Should be a value between 0 and 1. +#' @param position Position of the layer relative to other overlays. +#' @param maxZoom Closest zoom level the layer will be displayed on the map. +#' @param minZoom Furthest zoom level the layer will be displayed on the map. +#' @param from Date When paired with to defines the time range of data to display. #' Requires the Image Layer to be time enabled. -#' @param to Date When paired with from defines the time range of data to display. +#' @param to Date When paired with from defines the time range of data to display. #' Requires the Image Layer to be time enabled. -#' @param bandIds If there are multiple bands, you can specify which bands to export. -#' @param noData The pixel value representing no information. -#' @param noDataInterpretation Interpretation of the noData setting. -#' @param pixelType Leave pixelType as unspecified, or UNKNOWN, in most exportImage use cases, +#' @param bandIds If there are multiple bands, you can specify which bands to export. +#' @param noData The pixel value representing no information. +#' @param noDataInterpretation Interpretation of the noData setting. +#' @param pixelType Leave pixelType as unspecified, or UNKNOWN, in most exportImage use cases, #' unless such pixelType is desired. #' Possible values: C128, C64, F32, F64, S16, S32, S8, U1, U16, U2, U32, U4, U8, UNKNOWN. -#' @param renderingRule A JSON representation of a \href{http://resources.arcgis.com/en/help/arcgis-rest-api/#/Raster_function_objects/02r3000000rv000000/}{raster function} -#' @param mosaicRule A JSON representation of a \href{http://resources.arcgis.com/en/help/arcgis-rest-api/#/Mosaic_rule_objects/02r3000000s4000000/}{mosaic rule} -#' @param token If you pass a token in your options it will be included in all requests to the service. -#' @param proxy URL of an \href{https://developers.arcgis.com/javascript/jshelp/ags_proxy.html}{ArcGIS API for JavaScript proxy} or \href{https://github.com/Esri/resource-proxy}{ArcGIS Resource Proxy} to use for proxying requests. -#' @param useCors If this service should use CORS when making GET requests. +#' @param renderingRule A JSON representation of a \href{http://resources.arcgis.com/en/help/arcgis-rest-api/#/Raster_function_objects/02r3000000rv000000/}{raster function} +#' @param mosaicRule A JSON representation of a \href{http://resources.arcgis.com/en/help/arcgis-rest-api/#/Mosaic_rule_objects/02r3000000s4000000/}{mosaic rule} +#' @param token If you pass a token in your options it will be included in all requests to the service. +#' @param proxy URL of an \href{https://developers.arcgis.com/javascript/jshelp/ags_proxy.html}{ArcGIS API for JavaScript proxy} or \href{https://github.com/Esri/resource-proxy}{ArcGIS Resource Proxy} to use for proxying requests. +#' @param useCors If this service should use CORS when making GET requests. #' @param ... extra options #' @export imageMapLayerOptions <- function( - format = 'jpgpng', - f = 'json', - opacity = 1, - position = 'front', - maxZoom = NULL, - minZoom = NULL, + format = "jpgpng", + f = "json", + opacity = 1, + position = "front", + maxZoom = NULL, + minZoom = NULL, from = NULL, to = NULL, - bandIds = NULL, - noData = NULL, - noDataInterpretation = NULL, - pixelType = NULL, - renderingRule = NULL, - mosaicRule = NULL, - token = NULL, - proxy = NULL, - useCors = TRUE, + bandIds = NULL, + noData = NULL, + noDataInterpretation = NULL, + pixelType = NULL, + renderingRule = NULL, + mosaicRule = NULL, + token = NULL, + proxy = NULL, + useCors = TRUE, ... ) { leaflet::filterNULL(list( @@ -86,11 +86,11 @@ addEsriImageMapLayer <- function( popupFunction = NULL, popupOptions = NULL, layerId = NULL, group = NULL) { map <- addEsriDependency(map) - if(is.null(options)) { + if (is.null(options)) { options <- list() } leaflet::invokeMethod( map, leaflet::getMapData(map), - 'addEsriImageMapLayer', url, layerId, group, + "addEsriImageMapLayer", url, layerId, group, options, popupFunction, popupOptions) } diff --git a/R/tiledMapLayers.R b/R/tiledMapLayers.R index 7a6355e..eade5f1 100644 --- a/R/tiledMapLayers.R +++ b/R/tiledMapLayers.R @@ -2,10 +2,10 @@ #' Options for TiledMapLayer. #' #' @param correctZoomLevels Correct Zoom levels. -#' @param zoomOffsetAllowance If correctZoomLevels is enabled this controls the amount of tolerance for the difference at each scale level for remapping tile levels. -#' @param proxy URL of an \href{https://developers.arcgis.com/javascript/jshelp/ags_proxy.html}{ArcGIS API for JavaScript proxy} or \href{https://github.com/Esri/resource-proxy}{ArcGIS Resource Proxy} to use for proxying requests. -#' @param useCors Dictates if the service should use CORS when making GET requests. -#' @param token Use this token to authenticate all calls to the service. +#' @param zoomOffsetAllowance If correctZoomLevels is enabled this controls the amount of tolerance for the difference at each scale level for remapping tile levels. +#' @param proxy URL of an \href{https://developers.arcgis.com/javascript/jshelp/ags_proxy.html}{ArcGIS API for JavaScript proxy} or \href{https://github.com/Esri/resource-proxy}{ArcGIS Resource Proxy} to use for proxying requests. +#' @param useCors Dictates if the service should use CORS when making GET requests. +#' @param token Use this token to authenticate all calls to the service. #' @param tileOptions Other options for tile layer. You can pass \code{\link[leaflet]{tileOptions}()}. #' @export tiledMapLayerOptions <- function( @@ -22,7 +22,7 @@ tiledMapLayerOptions <- function( proxy = proxy, useCors = useCors, token = token - ),tileOptions)) + ), tileOptions)) } #' Access tiles from ArcGIS Online and ArcGIS Server to visualize and identify features. @@ -41,10 +41,10 @@ addEsriTiledMapLayer <- function( layerId = NULL, group = NULL) { map <- addEsriDependency(map) - if(is.null(options)) { + if (is.null(options)) { options <- list() } leaflet::invokeMethod( map, leaflet::getMapData(map), - 'addEsriTiledMapLayer', url, layerId, group, options) + "addEsriTiledMapLayer", url, layerId, group, options) } diff --git a/inst/examples/basemaps.R b/inst/examples/basemaps.R index 0409c0d..55578c0 100644 --- a/inst/examples/basemaps.R +++ b/inst/examples/basemaps.R @@ -8,13 +8,13 @@ library(leaflet.esri) basemaps <- esriBasemapLayers # Continental US -l <- leaflet() %>% setView(-98.35,39.5,3) +l <- leaflet() %>% setView(-98.35, 39.5, 3) purrr::walk(basemaps, function(basemap) { - l <<- l %>% addEsriBasemapLayer(key=basemap, autoLabels=TRUE, - group=basemap, - options = list(detectRetina=TRUE)) + l <<- l %>% addEsriBasemapLayer(key = basemap, autoLabels = TRUE, + group = basemap, + options = list(detectRetina = TRUE)) }) l %>% diff --git a/inst/examples/buildExamples.R b/inst/examples/buildExamples.R index 1dd2a4d..6f1816a 100644 --- a/inst/examples/buildExamples.R +++ b/inst/examples/buildExamples.R @@ -1,30 +1,30 @@ -examples.dir <- 'inst/examples' +examples_dir <- "inst/examples" -r.files <- as.list(dir(examples.dir, pattern = '.*\\.R$', full.names = TRUE)) -names(r.files) <- r.files +r_files <- as.list(dir(examples_dir, pattern = ".*\\.R$", full.names = TRUE)) +names(r_files) <- r_files # exclude self -r.files['inst/examples/buildExamples.R'] <- NULL -r.files <- unlist(r.files) -names(r.files) <- NULL +r_files["inst/examples/buildExamples.R"] <- NULL +r_files <- unlist(r_files) +names(r_files) <- NULL -rmd.files <- stringr::str_c(r.files,'md') -html.files <- stringr::str_c(tools::file_path_sans_ext(r.files),'html') +rmd_files <- stringr::str_c(r_files, "md") +html_files <- stringr::str_c(tools::file_path_sans_ext(r_files), "html") -r.files.mtimes <- file.info(r.files,extra_cols = FALSE)[,4] +r_files_mtimes <- file.info(r_files, extra_cols = FALSE)[, 4] -df <- data.frame(r.file=r.files, r.file.mtime = r.files.mtimes, - rmd.file = rmd.files, html.file = html.files, +df <- data.frame(r_file = r_files, r_file_mtime = r_files_mtimes, + rmd_file = rmd_files, html_file = html_files, stringsAsFactors = FALSE) -rm(r.files, rmd.files, html.files, r.files.mtimes) +rm(r_files, rmd_files, html_files, r_files_mtimes) -purrr::pwalk(df, function(r.file, r.file.mtime, rmd.file, html.file) { - if(!file.exists(rmd.file) || file.info(rmd.file)[,4] < r.file.mtime ) { - knitr::spin(r.file, knit = FALSE, format = 'Rmd') - rmarkdown::render(rmd.file,'html_document') +purrr::pwalk(df, function(r_file, r_file_mtime, rmd_file, html_file) { + if (!file.exists(rmd_file) || file.info(rmd_file)[, 4] < r_file_mtime ) { + knitr::spin(r_file, knit = FALSE, format = "Rmd") + rmarkdown::render(rmd_file, "html_document") } }) diff --git a/inst/examples/dynamicMapLayers.R b/inst/examples/dynamicMapLayers.R index 4048316..24fb1be 100644 --- a/inst/examples/dynamicMapLayers.R +++ b/inst/examples/dynamicMapLayers.R @@ -9,23 +9,23 @@ library(leaflet.esri) #' Custom Javascript for identifying features.

leaflet() %>% setView(-99.88, 37.71, 4) %>% - addEsriBasemapLayer(esriBasemapLayers$Gray, autoLabels = T) %>% + addEsriBasemapLayer(esriBasemapLayers$Gray, autoLabels = TRUE) %>% addControl(html = htmltools::HTML( - "Click on the map for Soil Order/ Sub-Order"), - layerId = 'selectedFeatures', position = 'bottomleft') %>% + "Click on the map for Soil Order/ Sub-Order"), + layerId = "selectedFeatures", position = "bottomleft") %>% addEsriDynamicMapLayer( - url='https://services.arcgisonline.com/arcgis/rest/services/Specialty/Soil_Survey_Map/MapServer', - layerId = 'soil') %>% + url = "https://services.arcgisonline.com/arcgis/rest/services/Specialty/Soil_Survey_Map/MapServer", + layerId = "soil") %>% htmlwidgets::onRender(htmlwidgets::JS( "function(el, x, data) { var map = this; var identifiedFeature; - var pane = document.getElementById('selectedFeatures'); + var pane = document.getElementById(\"selectedFeatures\"); - var soil = map.layerManager._byLayerId['tile\\nsoil']; + var soil = map.layerManager._byLayerId[\"tile\\nsoil\"]; - map.on('click', function (e) { - pane.innerHTML = 'Loading'; + map.on(\"click\", function (e) { + pane.innerHTML = \"Loading\"; if (identifiedFeature){ map.removeLayer(identifiedFeature); } @@ -34,13 +34,13 @@ leaflet() %>% setView(-99.88, 37.71, 4) %>% if (featureCollection.features.length > 0) { identifiedFeature = L.geoJson(featureCollection.features[0]).addTo(map); var soilDescription = - featureCollection.features[0].properties['Dominant Order'] + - ' - ' + - featureCollection.features[0].properties['Dominant Sub-Order']; + featureCollection.features[0].properties[\"Dominant Order\"] + + " - " + + featureCollection.features[0].properties[\"Dominant Sub-Order\"]; pane.innerHTML = soilDescription; } else { - pane.innerHTML = 'No features identified.'; + pane.innerHTML = \"No features identified.\"; } }); }); @@ -51,14 +51,14 @@ leaflet() %>% setView(-99.88, 37.71, 4) %>% popupFunc <- htmlwidgets::JS( "function (error, featureCollection) { - if(error || featureCollection.features.length === 0) { + if (error || featureCollection.features.length === 0) { return false; } else { - return 'Risk Level: ' + featureCollection.features[0].properties.CLASS_DESC; + return \"Risk Level: \" + featureCollection.features[0].properties.CLASS_DESC; } }") leaflet() %>% setView(-96.8, 38.5, 4) %>% - addEsriBasemapLayer(esriBasemapLayers$Gray, autoLabels = T) %>% + addEsriBasemapLayer(esriBasemapLayers$Gray, autoLabels = TRUE) %>% addEsriDynamicMapLayer( - url='https://maps7.arcgisonline.com/arcgis/rest/services/USDA_USFS_2014_Wildfire_Hazard_Potential/MapServer', popupFunction = popupFunc) + url = "https://maps7.arcgisonline.com/arcgis/rest/services/USDA_USFS_2014_Wildfire_Hazard_Potential/MapServer", popupFunction = popupFunc) diff --git a/inst/examples/featureLayers.R b/inst/examples/featureLayers.R index ceccb3a..94563fe 100644 --- a/inst/examples/featureLayers.R +++ b/inst/examples/featureLayers.R @@ -12,19 +12,19 @@ leaflet() %>% addEsriBasemapLayer(esriBasemapLayers$Streets) %>% setView(-122.667, 45.526, 13) %>% addEsriFeatureLayer( - url='https://services.arcgis.com/rOo16HdIMeOBI4Mb/arcgis/rest/services/Heritage_Trees_Portland/FeatureServer/0', + url = "https://services.arcgis.com/rOo16HdIMeOBI4Mb/arcgis/rest/services/Heritage_Trees_Portland/FeatureServer/0", useServiceSymbology = TRUE, - labelProperty = 'COMMON_NAM', labelOptions=labelOptions(textsize = '12px'), - popupProperty = JS("function(feature) { return L.Util.template('

{COMMON_NAM}


This tree is located at {ADDRESS} and its scientific name is {SCIENTIFIC}.', feature.properties);}")) + labelProperty = "COMMON_NAM", labelOptions = labelOptions(textsize = "12px"), + popupProperty = JS("function(feature) { return L.Util.template(\"

{COMMON_NAM}


This tree is located at {ADDRESS} and its scientific name is {SCIENTIFIC}.\", feature.properties);}")) #' ### Example 2 & 3 #' Here instead of using symbology set that was used to create the layer, we customize the icons used for markers.We also add custom Javascript functionality to interactively query the feature layer and filter the results.

busIcons <- awesomeIconList( - North = makeAwesomeIcon(icon = 'arrow-up', library = 'fa', markerColor = 'red'), - South = makeAwesomeIcon(icon = 'arrow-down', library = 'fa', markerColor = 'green'), - East = makeAwesomeIcon(icon = 'arrow-left', library = 'fa', markerColor = 'blue'), - West = makeAwesomeIcon(icon = 'arrow-right', library = 'fa', markerColor = 'darkpurple') + North = makeAwesomeIcon(icon = "arrow-up", library = "fa", markerColor = "red"), + South = makeAwesomeIcon(icon = "arrow-down", library = "fa", markerColor = "green"), + East = makeAwesomeIcon(icon = "arrow-left", library = "fa", markerColor = "blue"), + West = makeAwesomeIcon(icon = "arrow-right", library = "fa", markerColor = "darkpurple") ) control <- '

@@ -32,11 +32,11 @@ control <- '
Bus Direction
' @@ -46,20 +46,20 @@ leaflet() %>% addEsriBasemapLayer(esriBasemapLayers$Streets) %>% setView(-122.667, 45.526, 15) %>% addEsriFeatureLayer( - url='https://services.arcgis.com/rOo16HdIMeOBI4Mb/arcgis/rest/services/Trimet_Transit_Stops/FeatureServer/0', layerId = 'busStops', - labelProperty = 'stop_name', - markerIconProperty = 'direction', + url = "https://services.arcgis.com/rOo16HdIMeOBI4Mb/arcgis/rest/services/Trimet_Transit_Stops/FeatureServer/0", layerId = "busStops", + labelProperty = "stop_name", + markerIconProperty = "direction", markerOptions = markerOptions(opacity = 0.8, riseOnHover = TRUE), markerIcons = busIcons) %>% addControl(control, position = "topright") %>% htmlwidgets::onRender(JS(" function(el, x, data) { var myMap = this; - var direction = document.getElementById('direction'); + var direction = document.getElementById(\"direction\"); direction.addEventListener( - 'change', + \"change\", function() { - myMap.layerManager._byLayerId['geojson\\nbusStops'].setWhere(direction.value); + myMap.layerManager._byLayerId[\"geojson\\nbusStops\"].setWhere(direction.value); }); }")) @@ -69,9 +69,9 @@ leaflet() %>% addEsriBasemapLayer(esriBasemapLayers$Streets) %>% setView(-122.667, 45.526, 15) %>% addEsriFeatureLayer( - url='https://services.arcgis.com/rOo16HdIMeOBI4Mb/arcgis/rest/services/Trimet_Transit_Stops/FeatureServer/0', layerId = 'busStops', - labelProperty = 'stop_name', - markerIconProperty = 'direction', + url = "https://services.arcgis.com/rOo16HdIMeOBI4Mb/arcgis/rest/services/Trimet_Transit_Stops/FeatureServer/0", layerId = "busStops", + labelProperty = "stop_name", + markerIconProperty = "direction", markerOptions = markerOptions(opacity = 0.8, riseOnHover = TRUE), markerIcons = busIcons, clusterOptions = markerClusterOptions() @@ -84,7 +84,7 @@ leaflet() %>% addEsriBasemapLayer(esriBasemapLayers$Gray) %>% setView(-73.926, 40.706, 12) %>% addEsriHeatmapFeatureLayer( - url = 'https://services.arcgis.com/rOo16HdIMeOBI4Mb/ArcGIS/rest/services/Graffiti_Reports/FeatureServer/0', + url = "https://services.arcgis.com/rOo16HdIMeOBI4Mb/ArcGIS/rest/services/Graffiti_Reports/FeatureServer/0", radius = 12) #'

@@ -93,14 +93,14 @@ leaflet() %>% addEsriBasemapLayer(esriBasemapLayers$Gray) %>% setView(-73.926, 40.706, 12) %>% addEsriHeatmapFeatureLayer( - url = 'https://services.arcgis.com/rOo16HdIMeOBI4Mb/ArcGIS/rest/services/Graffiti_Reports/FeatureServer/0', + url = "https://services.arcgis.com/rOo16HdIMeOBI4Mb/ArcGIS/rest/services/Graffiti_Reports/FeatureServer/0", radius = 12, gradient = list( - `0.2` = '#ffffb2', - `0.4` = '#fd8d3c', - `0.6` = '#fd8d3c', - `0.8` = '#f03b20', - `1` = '#bd0026' + `0.2` = "#ffffb2", + `0.4` = "#fd8d3c", + `0.6` = "#fd8d3c", + `0.8` = "#f03b20", + `1` = "#bd0026" )) #' ### Example 6 @@ -110,21 +110,21 @@ leaflet() %>% addEsriBasemapLayer(esriBasemapLayers$Gray) %>% setView(-118.22, 33.836, 8) %>% addEsriFeatureLayer( - url = 'https://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/USA_Congressional_Districts/FeatureServer/0', - labelProperty = JS("function(feature){var props = feature.properties; return props.LAST_NAME+', '+props.NAME+ ' ['+props.PARTY+']'}"), - popupProperty = JS("function(feature){var props = feature.properties; return props.LAST_NAME+', '+props.NAME+ ' ['+props.PARTY+']'}"), - color = '#000000', weight =1 , fillOpacity = 0.5, - highlightOptions = highlightOptions(weight=2,fillOpacity=0.8,bringToFront=TRUE, - sendToBack=TRUE), + url = "https://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/USA_Congressional_Districts/FeatureServer/0", + labelProperty = JS("function(feature){var props = feature.properties; return props.LAST_NAME+\", \"+props.NAME+ \" [\"+props.PARTY+\"]\"}"), + popupProperty = JS("function(feature){var props = feature.properties; return props.LAST_NAME+\", \"+props.NAME+ \" [\"+props.PARTY+\"]\"}"), + color = "#000000", weight = 1, fillOpacity = 0.5, + highlightOptions = highlightOptions(weight = 2, fillOpacity = 0.8, bringToFront = TRUE, + sendToBack = TRUE), options = featureLayerOptions( simplifyFactor = 0.5, precision = 5, style = JS("function(feature){ var props = feature.properties; - if(props.PARTY === 'Democrat'){ - return {fillColor: 'blue'}; - } else if(props.PARTY === 'Republican'){ - return {fillColor: 'red'}; + if (props.PARTY === \"Democrat\"){ + return {fillColor: \"blue\"}; + } else if (props.PARTY === \"Republican\"){ + return {fillColor: \"red\"}; } else { - return {fillColor: 'white'}; + return {fillColor: \"white\"}; } }"))) diff --git a/inst/examples/imageMapLayers.R b/inst/examples/imageMapLayers.R index 2fd1369..f86b01d 100644 --- a/inst/examples/imageMapLayers.R +++ b/inst/examples/imageMapLayers.R @@ -12,7 +12,7 @@ leaflet() %>% addEsriBasemapLayer(esriBasemapLayers$Gray) %>% setView(30, 0, 3) %>% addEsriImageMapLayer( - url = 'https://sampleserver3.arcgisonline.com/ArcGIS/rest/services/World/MODIS/ImageServer', + url = "https://sampleserver3.arcgisonline.com/ArcGIS/rest/services/World/MODIS/ImageServer", options = imageMapLayerOptions(useCors = FALSE)) #'

@@ -21,7 +21,7 @@ leaflet() %>% addEsriBasemapLayer(esriBasemapLayers$Gray) %>% setView(-96.8, 38.5, 4) %>% addEsriImageMapLayer( - url = 'https://seamlessrnc.nauticalcharts.noaa.gov/arcgis/rest/services/RNC/NOAA_RNC/ImageServer') + url = "https://seamlessrnc.nauticalcharts.noaa.gov/arcgis/rest/services/RNC/NOAA_RNC/ImageServer") #' ### Example 3 #' Custom band Ids for infrared image layer.

@@ -30,8 +30,8 @@ leaflet() %>% addEsriBasemapLayer(esriBasemapLayers$Imagery) %>% setView(-120.23, 43.5, 5) %>% addEsriImageMapLayer( - url = 'http://imagery.oregonexplorer.info/arcgis/rest/services/NAIP_2011/NAIP_2011_Dynamic/ImageServer', - options = imageMapLayerOptions(bandIds = c(3,0,1))) + url = "http://imagery.oregonexplorer.info/arcgis/rest/services/NAIP_2011/NAIP_2011_Dynamic/ImageServer", + options = imageMapLayerOptions(bandIds = c(3, 0, 1))) #' ### Example 4 #' Custom rendering rule. Display an Image Service from ArcGIS Online or ArcGIS Server and apply a rendering rule to dynamically modify the display of the raster dataset. Rendering rules are created using a pre-defined set of raster functions contained in the ArcGIS Server 10 REST API. This example shows a raster image generated from raw LIDAR (Light Detection and Ranging) data rendered with a hillshade.

@@ -48,7 +48,7 @@ leaflet() %>% addEsriBasemapLayer(esriBasemapLayers$Imagery) %>% setView(-116.184826, 33.741114, 17) %>% addEsriImageMapLayer( - url = 'https://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Earthquakes/SanAndreasLidar/ImageServer', + url = "https://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Earthquakes/SanAndreasLidar/ImageServer", options = imageMapLayerOptions( useCors = FALSE, renderingRule = renderingRule)) @@ -59,26 +59,26 @@ leaflet() %>% #addEsriBasemapLayer(esriBasemapLayers$Imagery) %>% setView(-118.253147, 36.230577, 10) %>% addEsriImageMapLayer( - url = 'https://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Earthquakes/CaliforniaDEM/ImageServer', + url = "https://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Earthquakes/CaliforniaDEM/ImageServer", options = imageMapLayerOptions( useCors = FALSE, renderingRule = renderingRule), - layerId = 'hillshade') %>% - addControl('Click map for elevation', - layerId = 'pixelValue', position = 'topright') %>% + layerId = "hillshade") %>% + addControl("Click map for elevation", + layerId = "pixelValue", position = "topright") %>% htmlwidgets::onRender(htmlwidgets::JS( "function(el, x, data) { var map = this; var identifiedPixel; - var pane = document.getElementById('pixelValue'); - var hillshade = map.layerManager._byLayerId['tile\\nhillshade']; + var pane = document.getElementById(\"pixelValue\"); + var hillshade = map.layerManager._byLayerId[\"tile\\nhillshade\"]; - map.on('click', function (e) { - if(identifiedPixel){ - pane.innerHTML = 'Loading'; + map.on(\"click\", function (e) { + if (identifiedPixel){ + pane.innerHTML = \"Loading\"; } hillshade.identify().at(e.latlng).run(function(error, results){ identifiedPixel = results.pixel; - pane.innerHTML = identifiedPixel.properties.value + 'm'; + pane.innerHTML = identifiedPixel.properties.value + \"m\"; }); }); }")) @@ -87,7 +87,7 @@ leaflet() %>% #' Mosaic rule. Display an Image Service from ArcGIS Online or ArcGIS Server and apply a mosaic rule to dynamically control how the service combines rasters into a mosaic. This sample shows world temperature using the 8th raster only (August of 1950).

mosaicRule <- list( - mosaicMethod = 'esriMosaicLockRaster', + mosaicMethod = "esriMosaicLockRaster", lockRasterIds = list(8) ) @@ -95,5 +95,5 @@ leaflet() %>% addEsriBasemapLayer(esriBasemapLayers$Imagery) %>% setView(30, 20, 1) %>% addEsriImageMapLayer( - url = 'https://sampleserver3.arcgisonline.com/ArcGIS/rest/services/World/Temperature/ImageServer', + url = "https://sampleserver3.arcgisonline.com/ArcGIS/rest/services/World/Temperature/ImageServer", options = imageMapLayerOptions(useCors = FALSE, mosaicRule = mosaicRule)) diff --git a/inst/examples/multipleFeatureLayers.R b/inst/examples/multipleFeatureLayers.R index 74de51b..670fc95 100644 --- a/inst/examples/multipleFeatureLayers.R +++ b/inst/examples/multipleFeatureLayers.R @@ -10,7 +10,7 @@ library(leaflet.esri) -l <- leaflet(width='100%') %>% setView(-87.0369, 28.9072, 5) +l <- leaflet(width = "100%") %>% setView(-87.0369, 28.9072, 5) # Add a choice of BaseMaps @@ -18,29 +18,29 @@ purrr::walk( esriBasemapLayers, function(basemap) { l <<- l %>% addEsriBasemapLayer( - key=basemap, autoLabels=TRUE, - group=basemap, - options = list(detectRetina=TRUE)) + key = basemap, autoLabels = TRUE, + group = basemap, + options = list(detectRetina = TRUE)) }) # Map FeatureLayer Names to IDs layers <- list( - 'Black Coral' = 0, - 'Stony Coral' = 1, - 'Octocoral' = 2, - 'Sea Pen' = 3, - 'Sponge' = 4, - '50 Meter Bathymetry Contour' = 5, - '200 Meter Bathymetry Contour' = 6, - '500 Meter Bathymetry Contour' = 7, - '1000 Meter Bathymetry Contour' = 8) + "Black Coral" = 0, + "Stony Coral" = 1, + "Octocoral" = 2, + "Sea Pen" = 3, + "Sponge" = 4, + "50 Meter Bathymetry Contour" = 5, + "200 Meter Bathymetry Contour" = 6, + "500 Meter Bathymetry Contour" = 7, + "1000 Meter Bathymetry Contour" = 8) purrr::walk(names(layers), function(featureName) { l <<- l %>% addEsriFeatureLayer( - url = sprintf('http://portal.gulfcouncil.org/arcgis/rest/services/CoralWorkingGroup/GMFMCCoralandCoralReefs/MapServer/%d', layers[[featureName]]), - useServiceSymbology = TRUE , group = featureName, + url = sprintf("http://portal.gulfcouncil.org/arcgis/rest/services/CoralWorkingGroup/GMFMCCoralandCoralReefs/MapServer/%d", layers[[featureName]]), + useServiceSymbology = TRUE, group = featureName, options = featureLayerOptions(useCors = FALSE)) }) diff --git a/inst/examples/tiledMapLayers.R b/inst/examples/tiledMapLayers.R index 0951fe8..a32eb98 100644 --- a/inst/examples/tiledMapLayers.R +++ b/inst/examples/tiledMapLayers.R @@ -7,14 +7,14 @@ library(leaflet.esri) leaflet() %>% setView(-81.47, 30.70, 12) %>% addEsriTiledMapLayer( - url='https://services.arcgisonline.com/ArcGIS/rest/services/USA_Topo_Maps/MapServer') + url = "https://services.arcgisonline.com/ArcGIS/rest/services/USA_Topo_Maps/MapServer") leaflet() %>% setView(-155.04, 19.31, 9) %>% addEsriTiledMapLayer( - url= "https://services.arcgisonline.com/ArcGIS/rest/services/Specialty/World_Navigation_Charts/MapServer", - options = tiledMapLayerOptions(tileOptions = list(minZoom=3, maxZoom=10))) + url = "https://services.arcgisonline.com/ArcGIS/rest/services/Specialty/World_Navigation_Charts/MapServer", + options = tiledMapLayerOptions(tileOptions = list(minZoom = 3, maxZoom = 10))) leaflet() %>% setView(-77.0369, 38.9072, 14) %>% addEsriTiledMapLayer( - url='https://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer') + url = "https://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer")