简体   繁体   中英

find correct leaflet tile on Server give longitude / latitude

How can i find correct leaflet tile on Server give longitude / latitude.

I follow the Formula on slide 19 of this presentation: https://www.tu-chemnitz.de/urz/stammtisch/rsrc/vortrag-stammtisch.pdf (sry German).

Goal: Calculate (zoom, x and y) given longitude and latitude

Additional Information:

I found this docu https://mapserver.org/mapcache/services.html , which states that x is column number in zxy naming scheme and y the tow number.

What i tried:

#London
long = 51.52
lat = -0.18
zoom = 5
lambda = pi/180*long
phi = pi/180*lat

x = 2^zoom*(lambda + pi)/(2*pi)
y = 2^zoom*(pi - log(tan(phi) + 1/(cos(phi))))/(2*pi)
x
y

glue("https://tile.openstreetmap.org/{zoom}/{x}/{y}.png")

You can wrap the leaflet map in a really simple shiny app, and calculate on the fly the tile using leaflet shiny map events (info in the Inputs/Events section)

library(shiny)
library(leaflet)
library(glue)

ui <- fluidPage(
  leafletOutput('map'),
  textOutput('tile')
)

server <- function(input, output, session) {

  output$map <- renderLeaflet({
    leaflet() %>% 
      addTiles(options = tileOptions(noWrap = TRUE))
  })

  tile_finder <- eventReactive(input$map_click, {
    long <- input$map_click$lng
    lat <- input$map_click$lat
    zoom <- input$map_zoom
    lambda <- pi/180*long
    phi <- pi/180*lat

    x <- (2^zoom*(lambda + pi)/(2*pi))%/%1
    y <- (2^zoom*(pi - log(tan(phi) + 1/(cos(phi))))/(2*pi))%/%1

    glue("https://tile.openstreetmap.org/{zoom}/{x}/{y}.png")
  })

  output$tile <- renderText({
    tile_finder()
  })

}

shinyApp(ui, server)

You will get the tile info when clicking over the map, and the info appears below

在此处输入图像描述

The result for Paris, give this link https://tile.openstreetmap.org/8/129/88.png

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM