2017-03-23 2 views
0

Ich muss eine Beschriftung von Polygon (mit dem Namen der Region) zeigen, wenn Sie die Maus über das Polygon bewegen. Allerdings kann das Polygon nicht anklickbar sein, da ich diese Eigenschaft für einen anderen Teil meines Codes habe. Ist das möglich?R Leaflet: Ist es möglich, eine Polygonbeschriftung anzuzeigen, wenn das Polygon nicht anklickbar ist?

Wenn dies nicht möglich ist, könnte eine andere Lösung darin bestehen, einen Namen auf das Polygon zu schreiben. Ich weiß auch nicht, wie ich das machen soll. :/

Hier ist, wie mein Code

library(shiny) 
library(leaflet) 

ui <- bootstrapPage(
tags$style(type = "text/css", "html, body {width:100%;height:100%}"), 
leafletOutput("map", width = "100%", height = "100%") 
) 

# Load shapefiles 
shp_Tajo <- readOGR(dsn = "./Data/ES", layer = "Aqueduct_river_basins_TEJO", verbose = FALSE) 

server <- function(input, output, session){ 
output$map <- renderLeaflet({ 
     # Arguments controlling the looks of the basin polygon 
     dopacity = 0.3 
     dsmoothFactor = 1 
     dfillOpacity = 0.5 
     vcolors = c("red") 
     leaflet() %>% addTiles() %>% addPolygons(data = shp_Tajo, stroke = F, 
opacity = dopacity, smoothFactor = dsmoothFactor, color = vcolors[1], fillColor = vcolors[1], 
fillOpacity = dfillOpacity, highlightOptions = highlightOptions(color = "white", weight = 2, 
bringToFront = FALSE), options = pathOptions(clickable = FALSE), label = "Tajo", 
labelOptions = labelOptions(noHide = T, clickable = T, textOnly = TRUE, opacity=0.5,textsize='15px')) 
    }) 
} 

Die Form-Datei von http://riverbasins.wateractionhub.org/#find_lat_lng heruntergeladen werden kann, wo Sie wählen Spanien in der Dropdown-Menü so weit sieht.

Jede Hilfe würde sehr geschätzt werden!

+0

bitte ein reproduzierbares Beispiel liefern – HubertL

+0

@HubertL Ich habe jetzt ein reproduzierbares Beispiel aufgenommen. Vielen Dank für Ihren Kommentar. –

+0

Das ist viel besser, aber Sie haben keinen Hinweis darauf, wie das Klickereignis in Ihrem Code – HubertL

Antwort

0

Durch Ihre pathOptions Einstellungen Kommentierung aus, es funktioniert, wie Sie gedacht: Sie können auf eine beliebige Stelle außer für das Polygon und das Etikett des Polygons wird angezeigt bei mouse-over:

Arbeitsbeispiel:

enter image description here

library("shiny") 
library("rgdal") 
library("leaflet") 
library("ggmap") 

ui <- bootstrapPage(
    tags$style(type = "text/css", "html, body {width:100%;height:100%}"), 
    leafletOutput("map", width = "100%", height = "100%") 
) 

# Load shapefiles 
shp_Tajo <- readOGR(dsn = "./Data/ES", layer = "Aqueduct_river_basins_TEJO", verbose = FALSE) 

server <- function(input, output, session){ 
    output$map <- renderLeaflet({ 
    # Arguments controlling the looks of the basin polygon 
    dopacity = 0.3 
    dsmoothFactor = 1 
    dfillOpacity = 0.5 
    vcolors = c("red") 
    leaflet() %>% 
     addTiles() %>% 
     addPolygons(
     data = shp_Tajo 
     , stroke = FALSE 
     , opacity = dopacity 
     , smoothFactor = dsmoothFactor 
     , color = vcolors[1] 
     , fillColor = vcolors[1] 
     , fillOpacity = dfillOpacity 
     , highlightOptions = highlightOptions(color = "white", weight = 2, bringToFront = FALSE) 
     # , options = pathOptions(clickable = FALSE) 
     , label = "Tajo" 
     , labelOptions = labelOptions(noHide = TRUE, textOnly = TRUE, opacity = 0.5 , textsize='15px')) 
    }) 

    observeEvent(input$map_click, { 
    click <- input$map_click 
    clat <- click$lat 
    clng <- click$lng 

    leafletProxy('map') %>% 
     addCircles(
     lng = clng 
     , lat = clat 
     , group = 'circles' 
     , weight = 1 
     , radius = 5000 
     , color = 'black' 
     , fillColor = 'orange' 
     , fillOpacity = 0.5 
     , opacity = 1 
     ) 
    }) 
} 

shinyApp(ui, server) 
+0

Vielen Dank @mlegge! –

Verwandte Themen