leaflet

How can I access React state in my eventHandler?

半世苍凉 提交于 2021-01-24 07:22:36
问题 This is my state: const [markers, setMarkers] = useState([]) I initialise a Leaflet map in a useEffect hook. It has a click eventHandler. useEffect(() => { map.current = Leaflet.map('mapid').setView([46.378333, 13.836667], 12) . . . map.current.on('click', onMapClick) }, [] Inside that onMapClick I create a marker on the map and add it to the state: const onMapClick = useCallback((event) => { console.log('onMapClick markers', markers) const marker = Leaflet.marker(event.latlng, { draggable:

Add Polygon programmatically in Leaflet L.Draw plugin

假如想象 提交于 2021-01-21 07:28:45
问题 Is there a way to add a polygon programmatically using the Leaflet draw plugin? https://github.com/Leaflet/Leaflet.draw For example: click a button and add a square that can be edited by the plugin. 回答1: You just need to add your polygon (or whatever other layer that you want to be editable) to the Feature Group that you pass to the edit.featureGroup option of your L.Control.Draw control. var editableLayers = L.featureGroup().addTo(map); var drawControl = new L.Control.Draw({ edit: {

Leaflet: How can i show layer only inside a polygon

假如想象 提交于 2021-01-20 09:24:07
问题 Actually i'm working with Leaflet but when i add a leaftlet.webglheatmap layer it uses the entire screen... I need to show only the data (colour) inside a geoJson polygon, instead of all the map: I talked with the webglheatmap developer but he told me to create a new shape with webgl, but that is not an option in this minute I tried Leaflet.Snogylop too, but it just draw a shape outside my map and with some colours it doesnt do the effect. Thanks in advice 回答1: If I am interpreting your

How do I clear a leaflet map in react so I can map fresh data?

耗尽温柔 提交于 2021-01-07 04:10:01
问题 I am attempting to clear a leaflet map in react when fetching new data to map, and i am unsure how to approach this. I saw this post but not sure how exactly to apply it. Right now I have a function that fetches 1 of 2 geojsons I have loaded. App.js //SWAP FILES AS EXAMPLE fetchData = () => { //MAP SHOULD CLEAR EVERYTIME NEW DATA IS FETCHED if(this.state.loaded === 1) { fetch( "https://raw.githack.com/datafaust/raw/main/cruise-prototype/hh_2020112300_2020120623_Saturday_02.geojson" ) .then(

How do I clear a leaflet map in react so I can map fresh data?

这一生的挚爱 提交于 2021-01-07 04:09:55
问题 I am attempting to clear a leaflet map in react when fetching new data to map, and i am unsure how to approach this. I saw this post but not sure how exactly to apply it. Right now I have a function that fetches 1 of 2 geojsons I have loaded. App.js //SWAP FILES AS EXAMPLE fetchData = () => { //MAP SHOULD CLEAR EVERYTIME NEW DATA IS FETCHED if(this.state.loaded === 1) { fetch( "https://raw.githack.com/datafaust/raw/main/cruise-prototype/hh_2020112300_2020120623_Saturday_02.geojson" ) .then(

R leaflet highlight options

社会主义新天地 提交于 2021-01-04 04:19:29
问题 I am highlighting a line on R leaflet using the following command library(leaflet) m = leaflet() %>% addTiles(group = "OpenStreetMap") x <- c(1,5,4,8) y <- c(1,3,4,7) data = sp::SpatialLines(list(sp::Lines(sp::Line(cbind(x,y)), ID="a"))) addPolylines(smoothFactor = 0.4, map = m, data=data, opacity = 0.3, weight = 2, color = "black", label = "text", popup = "text1", highlightOptions = highlightOptions(bringToFront = TRUE, opacity = 1, weight = 5, sendToBack = FALSE, color = "white")) Is there

Customize clustering of markers on Leaflet maps

别来无恙 提交于 2021-01-03 08:46:05
问题 I'm working on an app with a large number of markers and would like to cluster them. I found Leaflet.markercluster and it does a good job. However, I would like to customize the clustering of the markers. Specifically, I want to cluster my markers depending on the country they are in. I don't want a cluster which includes all markers in Europe but instead several clusters by country. Is there any way to achieve this? 回答1: You can create several clusters and add your markers to them

React-Leaflet: Scale markers after zooming

此生再无相见时 提交于 2021-01-01 09:13:09
问题 I'm trying to achieve having markers on a CRS map (specifically a circular avatar with initials) that scale with the map's zoom (they would appear larger or smaller depending on the zoom, not remain the same size), and have been having considerable difficulty achieving performance. I've tried two different components for the avatars, (still not sure which is right solution): Circle component with a simple, permanent tooltip inside (this component is convenient because it automatically scales)

React-Leaflet: Scale markers after zooming

℡╲_俬逩灬. 提交于 2021-01-01 09:08:32
问题 I'm trying to achieve having markers on a CRS map (specifically a circular avatar with initials) that scale with the map's zoom (they would appear larger or smaller depending on the zoom, not remain the same size), and have been having considerable difficulty achieving performance. I've tried two different components for the avatars, (still not sure which is right solution): Circle component with a simple, permanent tooltip inside (this component is convenient because it automatically scales)

React-Leaflet: Scale markers after zooming

非 Y 不嫁゛ 提交于 2021-01-01 09:08:29
问题 I'm trying to achieve having markers on a CRS map (specifically a circular avatar with initials) that scale with the map's zoom (they would appear larger or smaller depending on the zoom, not remain the same size), and have been having considerable difficulty achieving performance. I've tried two different components for the avatars, (still not sure which is right solution): Circle component with a simple, permanent tooltip inside (this component is convenient because it automatically scales)