GithubHelp home page GithubHelp logo

Comments (10)

vbonhomme avatar vbonhomme commented on July 24, 2024 1

Thanks a lot, that unlocks some key aspect of my problem ! I'll dig it further and let you know.

from mapedit.

vbonhomme avatar vbonhomme commented on July 24, 2024

also asked the question in SO, there

from mapedit.

tim-salabim avatar tim-salabim commented on July 24, 2024

See also these two threads

rstudio/leaflet#371
#54

leaflet currently does not render raster images with arbitrary or no crs. In an early version of mapview we circumvented this with the approach you mention via scaling the coordinates to lie between 0 and 1. However, I agree that this is not a solution, especially for digitizing.
One hope I have is that whenever leaflet gets updated to leafletjs 1.x this issue will be resolved. @timelyportfolio have you ever tested whether rasters work with L.CRS.Simple in the leaflet 1.x branch? Or would it be possible to enable editMap to work with mapview::plainview which is used when native.crs = TRUE?

mapview(r, native.crs = TRUE)

from mapedit.

vbonhomme avatar vbonhomme commented on July 24, 2024

Hi @tim-salabim and @timelyportfolio (me again!)

With mapview(r, native.crs=TRUE) I got the (seen-elsewhere) following error:

Error in round(size) : non-numeric argument to mathematical function
In addition: Warning message:
In rasterCheckSize(x, maxpixels = maxpixels) :
  maximum number of pixels for Raster* viewing is #BEBEBE80 ; 
the supplied Raster* has 100520 
 ... decreasing Raster* resolution to #BEBEBE80 pixels
 to view full resolution set 'maxpixels =  100520 '

plainview(r)works though, and if we could do the same things that we do with a regular editmap I think the main problem would be solved!

from mapedit.

tim-salabim avatar tim-salabim commented on July 24, 2024

This has been fixed recently, see r-spatial/mapview#111
So if you install mapview from github you should be able to use native.crs = TRUE

devtools::install_github("r-spatial/mapview@develop")

from mapedit.

vbonhomme avatar vbonhomme commented on July 24, 2024

indeed!

from mapedit.

vbonhomme avatar vbonhomme commented on July 24, 2024

@timelyportfolio may I ping you to have your feeling about what @tim-salabim suggested? Cheers!

from mapedit.

timelyportfolio avatar timelyportfolio commented on July 24, 2024

Sure, feel free to ping me. Might be a little slower in responding over the holidays. Cheers!

from mapedit.

vbonhomme avatar vbonhomme commented on July 24, 2024

@timelyportfolio , that was a question, perhaps too politely asked ;-)

from mapedit.

timelyportfolio avatar timelyportfolio commented on July 24, 2024

Ok, I understand now. I very likely am headed down the wrong path, so feel free to set me straight.

  1. addRasterImage() creates a tile layer. Is this necessary, or is the L.imageOverlay as in example sufficient?

  2. This might be helpful down the road Leaflet/Leaflet.draw#611.

Some code as a demonstration of the very little that I accomplished.

library(jpeg)
library(raster)
library(leaflet)
library(leaflet.extras)
library(mapview)
library(mapedit)

# dl an image
path <- "https://upload.wikimedia.org/wikipedia/commons/thumb/5/58/CheHigh.jpg/280px-CheHigh.jpg"
che <- tempfile()
download.file(path, che, mode="wb")
im <- jpeg::readJPEG(che)

# prepare a raster from it
r  <- raster(xmn=0, xmx=1,
             ymn=0, ymx=nrow(im)/ncol(im),
             ncols=ncol(im), nrows=nrow(im))
r <- setValues(r, as.numeric(t(im)))

# prepare the leaflet
lf <- leaflet(
  options = leafletOptions(
    crs = leafletCRS("L.CRS.Simple"),
    minZoom = 1,
    maxZoom = 10
  )
) %>%
  setView(0, 0, zoom=3)

lf2 <- htmlwidgets::onRender(
  lf,
sprintf(
"
  function(el, x) {
    var map = this;
    var w = %s,
        h = %s,
        url = 'http://upload.wikimedia.org/wikipedia/commons/thumb/5/58/CheHigh.jpg/280px-CheHigh.jpg';
    
    // calculate the edges of the image, in coordinate space
    var southWest = map.unproject([0, h], 3);
    var northEast = map.unproject([w, 0], 3);
    var bounds = new L.LatLngBounds(southWest, northEast);

    L.imageOverlay(url, bounds).addTo(map);
  }
",
  dim(im)[2],
  dim(im)[1]
)
)

editMap(lf2)

leaflet.extras uses layer.toGeoJSON() which does not gives projected coordinates unfortunately (or at least I think unfortunately). I believe we might need map.latLngToLayerPoint instead.

I know this isn't much, but maybe it will get us one step further towards something usable.

from mapedit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.