trafficonese / leaflet.esri

ESRI Plugin for Leaflet R Package
https://bhaskarvk.github.io/leaflet.esri/
GNU General Public License v3.0
35 stars 7 forks source link

Syntax for imageMapLayerOptions from/to #7

Open jclarkology opened 6 years ago

jclarkology commented 6 years ago

I'm trying to implement a raster time-series following this example: https://landsat.arcgis.com/arcgis/rest/services/LandsatGLS/MS/ImageServer However, I'm struggling with the syntax of the "from" and "to" arguments. The ESRI example just calls a single year:

        from: new Date(timeInput.value),
        to: new Date(timeInput.value)

Passing a numeric 'from' and 'to' doesn't return any tiles:

leaflet() %>%
  setView(113.8, .52, zoom = 8) %>%
  leaflet.esri::addEsriImageMapLayer(
    "https://landsat.arcgis.com/arcgis/rest/services/Landsat/PS/ImageServer",
    imageMapLayerOptions(
      from = 2000,
      to = 2001,
      renderingRule = "Pansharpened Enhanced with DRA"
    ),
    group = "Landsat", layerId = "landsat") 

Which doesn't surprise me since I'm not passing it as the JS Date class. However, passing an R Date DOES return tiles, but the from/to constraints have no effect. These both return the same imagery:

leaflet() %>%
  setView(113.8, .52, zoom = 8) %>%
  leaflet.esri::addEsriImageMapLayer(
    "https://landsat.arcgis.com/arcgis/rest/services/Landsat/PS/ImageServer",
    imageMapLayerOptions(
      from = as.Date("2006-01-01"),
      to = as.Date("2010-01-01"),
      renderingRule = "Pansharpened Enhanced with DRA"
    ),
    group = "Landsat", layerId = "landsat") 

leaflet() %>%
  setView(113.8, .52, zoom = 8) %>%
  leaflet.esri::addEsriImageMapLayer(
    "https://landsat.arcgis.com/arcgis/rest/services/Landsat/PS/ImageServer",
    imageMapLayerOptions(
      from = as.Date("2000-01-01"),
      to = as.Date("2001-01-01"),
      renderingRule = "Pansharpened Enhanced with DRA"
    ),
    group = "Landsat2", layerId = "landsat2") 

Not sure whether syntax is the issue, maybe it needs to apply a mosaicRule? Any guidance you can provide would be greatly appreciated.

bhaskarvk commented 6 years ago

I will take a look this weekend and give you an answer.

jclarkology commented 6 years ago

Hi Bhaskar,

Not sure whether you've had time to take a look at this. I've made some progress, but would still like to confirm this is the correct syntax/best practice. This seems to be working:

leaflet() %>%
  setView(113.8, .52, zoom = 8) %>%
  leaflet.esri::addEsriImageMapLayer(
    "https://landsat.arcgis.com/arcgis/rest/services/Landsat/PS/ImageServer",
    imageMapLayerOptions(
      from = JS('new Date(\'1999\')'),
      to = JS('new Date(\'2001\')'),
      renderingRule = "Pansharpened Enhanced with DRA"
    ),
    group = "Landsat2", layerId = "landsat2") 

leaflet() %>%
  setView(113.8, .52, zoom = 8) %>%
  leaflet.esri::addEsriImageMapLayer(
    "https://landsat.arcgis.com/arcgis/rest/services/Landsat/PS/ImageServer",
    imageMapLayerOptions(
      from = JS('new Date(\'2004\')'),
      to = JS('new Date(\'2006\')'),
      renderingRule = "Pansharpened Enhanced with DRA"
    ),
    group = "Landsat2", layerId = "landsat2") 

The trick was to pass the year within htmlwidgets::JS() following the syntax from the ESRI example, AND ensure the date string is quoted to ensure it's parsed by Javascript.

Thank you for this package and your other fantastic contributions!