Comments (3)
@mennodekker, for the mere mortal, could you provide a quick example on how to use the click event either on the server or client side (or both). I'm migrating from @jcheng5 leaflet to @rstudio leaflet package and having difficulties replicating the onclick and onmouseover events using this version. That'd be really helpful, thanks.
from leaflet.
I did the same thing. The problem I had was that for geojson layers the mapid is not set. The work around until it is fixed is to use undefined.
As snippet of code that works with current implentation:
For server.R (notice the normal map click uses myMap and geosjon undefined)
Lmap = leaflet() %>% setView(5.266007882805511, 16.5234375, zoom = 1.5)
observe({
evt <- input$myMap_click
if (is.null(evt))
return()
isolate({
# An empty part of the map was clicked.
# Null out the selected feature.
values$selectedFeature <- NULL
})
})
observe({
evt <- input$undefined_geojson_click
if (is.null(evt))
return()
isolate({
# A GeoJSON feature was clicked. Save its properties
# to selectedFeature.
values$selectedFeature <- evt$properties
})
})
Lmap = Lmap %>% addGeoJSON(geo)
output$myMap <- renderLeaflet(Lmap)
For ui.R
leafletOutput('myMap', width="100%", 380)
from leaflet.
Perfect, thanks so much!
What is the equivalent method if features are loaded with addPolygons() instead of addGeoJSON()? Would input$myMap_click
and input$myMap_mouseover
return the polygon layerId?
from leaflet.
Related Issues (20)
- toggle baseGroups legends in the same way as overlayGroups in addLayersControl HOT 1
- Proj4Leaflet-TMS.R example is broken; broken TMS in Leaflet is possibly the culprit! HOT 2
- tms = TRUE not working with known TMS provider (from NASA!) HOT 2
- Leaflet muddling RGB rasters from terra HOT 1
- No documentation on the Polyline 'offset' functionality
- Error in addLegend: unused arguments HOT 2
- addTiles does not allow display of self-hosted vector tiles
- Specifying labels as zero-length character vector causes error
- Update docs to use `{sf}` or `{terra}` HOT 1
- Remove vignettes/articles/nc after successful site build
- Broken basemaps on {pkgdown} site HOT 3
- Specifying Pop-up Location HOT 2
- modify icon size
- dependencies missing in v.2.2.2 HOT 2
- Maps are blank when previewing in RStudio on Windows with R 4.4.0 HOT 6
- Leaflet maps don't appear in RStudio Viewer Pane (Windows + R 4.4 HOT 1
- Layers Control not working in R-4.4.0 in MacOS X Sononma HOT 5
- Checking for correctly input `leaflet` provider strings HOT 2
- Adding labels to polylines increases line opacity HOT 2
- Are there plans to upgrade to a newer leaflet.js
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from leaflet.