How to differentiate markers in Leaflet - leaflet

I am working on Openstreet map. I have displayed markers in leaflet, but I want to design an interface and assign different groups to the markers. E.g. when an user clicks on "Hospitals", all the hospitals should be displayed on the map.

You should study this tutorial.
What you can do is group all your marker in the same category in a L.LayerGroup,
then the user will be able to add or remove it at will with the control.

Related

How to detect when user does not click on a layer? Leaflet

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

Put markers or layers on tags in OSM

I want to use openstreetmap to put a marker or zone an area with an overlay for certain locations like farmland or commercial buildings.
Is it possible to do a custom map, where I pan around and put a marker, or an area overlay on these specific places?
Looking at the official openstreetmap client I see now way of exposing this information.
For a farmland I want to add a farm building marker, and for a commercial building a commercial marker for example.

Mapbox: show only one country on base map?

I'm using Mapbox GL JS. Is there any way I can style my base layer to look like the Mapbox Light example, but showing only the UK?
I assume I would use Mapbox Studio to build my own base layer, but I can't see any way in Studio to filter by country.
If that's not possible, is there any way I could show labels on the UK only, and show other countries as filled polygons? (As per this unanswered question.)
Unfortunately it is not possible to filter by a certain geography when selecting the data source for a layer. If you're working with Mapbox's tiles, they'll always cover the entire planet.
There is the possibility to restrict the map to a certain (rectangular) bounds, with the map.setMaxBounds method (https://www.mapbox.com/mapbox-gl-js/api/#Map#setMaxBounds). This might work reasonably well since you want to restrict the view to the UK, but might not be suitable depending on the geometry you want to restrict the view to.
As a workaround you could create a dataset and add a polygon that covers the entire planet except for the extent you want to show in your map. Then add this dataset in your style as the top most layer and style it with whatever you'd like the empty space in your map to look like.
The workaround has been also suggested in this SO answer, if you can get maptiles for the UK only (the SO answer gives a link, but for Germany) you can
upload them to Mapbox as a dataset, export it to tilesets, and then
to a map as a layer. Delete all other layers
You have also the possibility to Style a single country in Mapbox
studio ref this tutorial. The other countries are still shown, but you can style your map in a way to highlight UK
There is a option that allows you to show only one country highlighted. But drawback is, you lose all the layers and tile-level details. Here is the link https://www.mapbox.com/videos/how-to/map-a-single-country-in-mapbox-studio/.
But if you want to include the tile details as well as whole world map but in that map only one or two or custom amount of countries highlighted, then, from above link of Natural Earth download the zipped file of ne_10m_admin_0_countries and upload.
Go back to your map style, and instead of making a blank one. Add another layer of ne_10m_admin_0_countries in your current map. Select the country in the filter option (in same way as shown in video). And change its opacity. That's it.
Hope it helps. Have a great day.

How to hide map but show other layers

I am developing a simple map app using Google Maps API v2 for Android.
The data that is displayed are:
a. The map layer (the satellite view from Google Maps);
b. The political map layer (KML);
c. Some custom markers from user (KML).
I would like to add a button to toggle show/hide each layer. I can do it for layers "b" and "c" (e.g. Hiding/showing a kml layer on customized google maps depending of the view), but how to do it with layer "a"???
I searched a lot and did not find how to do it using only that API. Is it possible?
The mapType MAP_TYPE_NONE positions the custom tiles according to the camera position, but does not show its own map tiles.

Mapbox zoom to location based on url

I have a main map landing page of the U.S. which shows my map and all the pins on it, then there are individual pages for each state with specific content related to them, that also show the map. I am wondering if it is possible to have the map zoom into the states location when that url is clicked. e.g. When you click to go to the Colorado page, the map zooms and centers on Colorado, instead of going to the default view on the main map landing page.
It would work like the geocoder, if you type Colorado, it zoom and centers on the state.
The initially position map with geocode example is probably close to what you're looking for.