I am using leafletjs in a project. On the map I have several polygons and markers. There is a click event on all of them to display some information when one of them is clicked. I would like to take the information away if the user clicks on a 'blank' part of the map (not on any polygons or markers). I know the map has the 'click' event but so far I am struggling to find a way to detect if the user clicked on a layer. Any advice?
you can use preclick event to clear all the data
https://leafletjs.com/reference-1.2.0.html#map-preclick
Related
In my Application Project i have set up a Xamarin Forms Map which centers on the users position. Now i wanted to let an icon show up when the user dragged the map somewhere to recenter on the position of the user. Unfortunately xamarin forms maps only has ja MapClicked event so eve3n when the map was dragged i have to click another time on the map so that the event is triggered. I tried using geastrue recognizers as well but somehow they neither work on the map directly nor when i impliment them on the grid over the map.
After some time i thought about checking wether the map position equals the users position and i found this tutorial https://xamarinhowto.com/xamarin-forms-maps-getting-location-radius-of-users-input/ unfortunately this did not work for me either since the code could not handel .Log() for strings.
Do you have a solution for my problem? The recenter icon should just appear as it is in Ios Maps when i dragged the map from my position.
Fairly new to Mapbox and getting there (slowly).
I have a map initially loaded at zoom level 1 for use in a web browser. When a user clicks on a marker, it'll center and zoom to level 10.
When that marker loses focus, I'd like to zoom back out to level 1.
This page discussing web applications does it (link below), but there doesn't seem to be (that I can find - sorry!) any documentation on how to achieve this.
https://docs.mapbox.com/help/getting-started/web-apps/
Any and all help appreciated!
For the first event, to zoom in when clicking a marker, you could adapt this example to zoom in addition to panning when calling flyTo
https://docs.mapbox.com/mapbox-gl-js/example/center-on-feature/
For the second part, you'd need to add a listener for another event depending on what you have in mind by "losing focus".
https://docs.mapbox.com/mapbox-gl-js/api/map/#map-events
UPD: Done. Look at this beautiful polygon.
UPD: In Flutter / openstreetmap, I want to let users draw a polygon by tapping a map and/or clicking a button. The polygon should be not filled. I need a very simple example just to get an idea of how it works.
The final task is:
I am making a flutter application that should give the user the ability to get information about markers located within a certain area on the map. I use osm. By pressing the button, the user initiates the construction of an arbitrary polygon, each corner of which is formed at the place of the next pressing of the button. When the construction of the polygon is completed, the objects inside the polygon are shown, the rest are hidden or not built. After that, the cycle ends by clearing the map.
I haven't found any solution for osm. I would appreciate any help. I don't have any code yet)
You can use the flutter_map library, I'm sure you can understand the documentation and how to set it up.
Then use PolygonLayerOptions(polygons: [Polygon(points: polygonList)]) as a layer on top of the OSM layer. Then set up the list polygonList and use the FlutterMap()'s onTap callback to get the position at which the user tapped and add the LatLng to the polygonList list. There are multiple other configuration options within the Polygon() constructor, and those can be found through IntelliSense or similar. To have no fill, just set the color to transparent.
I use this method (or a very similar one) for my app which lets users download areas of map. The user taps the top left and bottom right of a rectangular area they want to download, by code calculates the top right and bottom left, and a polygon is drawn to show the user exactly where they tapped. Make sure to use setState() or similar.
I have a mapbox project that I need to be able to re-center the map when a popup closes. Right now, clicking a marker will pan the map and after the user closes the popup they are left with the map panned over to the new location. I simply need the map to recenter to the original location I set as my map center.
I've not found a method using the mapbox api so I don't have any code to start. I'm more looking for someone who might have experience with such a configuration.
Since mapbox.js is built on top of leaflet you can use the Leaflet API.
You can listen for popupclose events. Then you can call map.setView() and center the map at the original position.
Here is a working example
I have a offline map tiles, i display it and also zoom in zoom out functionality in that and it's working very well, but now i want to drop multiple pins on offline map tiles and also want to get lat-long of that drop pin how it's possible ? please help me.
you will get definitely solution form this link Offline Maps iPhone
I have check and get lat and long when i click on map. so on click event u will drop a pin.
in this link u will see the answer which is given by Ruben Esposito.
MAy be it help.