An example for a custom layer for the IHM site.
The IHM site uses MapLibre under the hood, this means you need to know a bit about MapLible in order to be able to show a custom layer. There are many guides available online, I personally like the examples page the most. The main things to understand is that there are three part to presenting a custom layer in IHM site
- You need a data source
- You need to style it using MapLibre rules
- You need to add a layer to the IHM site using the IHM interface
There are 3 main option to choose for the data source:
- Using the IHM available sources, these can be seen seen in the IHM styles, for example you can see it in the Hiking Style
- Use overpass turbo query
- Generate a geojson file and store it
The content of the files was not copy paseted here, so you'll need to read this carefully to get it working... :-)
This is the most simple use case. The following example uses the IHM data source to show accesible routes: https://github.com/HarelM/IHMAccessibleRoutes/tree/main This mean there's only a style.json that uses the IHM source and all you need to do is style it the way you want, you can have a look at the IHM style to understand how to get the data from the relevant layer.
When the data is not available in the IHM data source, and is available in OSM (might also be zoom related) you can use the overpass to get the data. The following is an exmaple of a style.json that uses the overpass turbo source https://gist.githubusercontent.com/zstadler/c9ce8dc115c955fde99eb6b135e0d8fe/raw/30b4396054dd82deb2f1020502db15487819e9a1/Overpass-overlay-example.json The steps to following is:
- Go to Overpass Turbo and create the query you would like to get the data for. Here is an example of a query: https://overpass-turbo.eu/s/1nyV
- If the query is OK and you see the relevant resutls take the query text (
nw ...
in the above case) to https://www.urlencoder.org/ and encode it, - Using the encoded query add it to the
data
field of a geojson source in the publicly availbale style.json file
The following example uses a geojson file that is stored and updated in the repositry: https://github.com/amiad/IHMGeoJSONWaterholes You need to make sure the geojson source is CORS enabled and uses the WGS 84reference system
If you would like to have different behavior for a base layer or overlay you can use the following tag in the layer metadata: { "IHM:Overlay": false }
for each layer that you would like to hide when setting this style as an overlay.
CORS enabled can be achieved with GitHub and Githack as can be seen in this repository.
If you need icons that are not part of the IHM site sprite you can write a full url to an image in the icon field of the layer and the IHM site will show that icon.
You can use the following address inside IHM site's custom layer control to see a layer with the IHM icon somewhere in the south of israel https://raw.githubusercontent.com/HarelM/IHMMapboxMapExample/main/style.json
Surf to https://israelhiking.osm.org.il/map/9.39/31.6277/35.2993 to see the icon