Mapbox gl: refer to different tile sources with different zoom levels - mapbox-gl-js

I'm coding a map and I have the following raster source:
{
type: 'raster',
tiles: [
LinkA,
LinkB
],
tileSize: 256,
scheme: 'tms'
}
I want to switch to LinkB from a certain zoom level, how can I do that?

I don't think there's a way to do that within one source.
But you could create two sources, each with a different minzoom and maxzoom, and one layer for each. The end result should be pretty similar.
EDIT
For completeness, I think it would be possible to use transformRequest to modify the URL when a request is made, within a single raster source. A more complicated solution though.

Related

Extrapolate Coordinates form Leaflet map

I'm planning a climbing trip and I wanted to retrieve the climbing locations from a leaflet map.
I thought I could use chromedriver and selenium to get the information I wanted but I'm having difficulty scanning through all markers since I can't understand where all the informations are stored.
Could someone guide me through how I could get the information? (also without using selenium)
The map in question is: https://www.climbingsardinia.com/topos/maps/
Thank you in advance.
in that page you will see a global variable called cttm_markers, it contains all markers informations and relative coordinates.
For example, cttm_markers[0][[0].additionalData.title evaluates "M.te Arci – Trebina Longa".Further, cttm_markers[0][[0]._latlng is an object {lat,lng} that contains coordinates.
Try to open console and paste this: JSON.stringify(cttm_markers[0].map(c=>({title:c.additionalData.title,latlng:c._latlng}))), it will print a json.
One way to do it is to get some information on one of the markers and use this to search the request reponses made by the page (you can do this in the debug tools, usually opened with F12). One of the markers for example reveals the location "Grighini". The base request redirects to (in my case) https://www.climbingsardinia.com/topos/maps/?doing_wp_cron=1651158093.0027918815612792968750
Searching the response, reveals that in line 1908 there's the string "Grighini". This line contains a serialized JSON array, containing the markers.

Getting routes on openstreetmaps using OSRM

I've been trying to get a list of co-ordinates in a route from point A to B using OSRM with the following request:
GET http://router.project-osrm.org/viaroute?hl=en&loc=47.064970,15.458470&loc=47.071100,15.476760
However, on opening the url, i find the 'via_points' tag containing only two co-ordinates. Surely, that can't be the entire route? Anything I'm missing here? Is there any other way of generating the list of route co-ordinates with OSRM? Thanks
The route is contained in the route_geometry object. It is an encoded polyline. If you don't want to uncompress it yourself you can disable compression via compression=false:
http://router.project-osrm.org/viaroute?compression=false&hl=en&loc=47.064970,15.458470&loc=47.071100,15.476760
Not sure what the via_points contains. OSRM's documentation seems to be outdated. Maybe they are just your start and end points snapped to the nearest road or something similar.

Mapbox Directions Instructions in Metric

I am trying to work with the Mapbox Directions plugin. I have found no documentation for the various controls indicated in the example here:
https://www.mapbox.com/mapbox.js/example/v1.0.0/mapbox-directions/
The Inputs control doesn't work well at all so I'm using my own control and have got it to display the origin and destination markers, route highlight, and instructions using code similar to this:
var loStartLatLng = L.latLng(53.5, -113.5);
var loEndLatLng = L.latLng(53.5012, -113.5012);
var loDirections = L.mapbox.directions({
profile: 'mapbox.driving'
});
loDirections.setOrigin(loStartLatLng);
loDirections.setDestination(loEndLatLng);
loDirections.query();
var loDirectionsLayer = L.mapbox.directions.layer(loDirections).addTo(moMap);
var loDirectionsErrorsControl = L.mapbox.directions.errorsControl('divRouteErrors', loDirections);
var loDirectionsRoutesControl = L.mapbox.directions.routesControl('divAlternateRoutes', loDirections);
var loDirectionsInstructionsControl = L.mapbox.directions.instructionsControl('divRouteInstructions', loDirections);
I have not found documentation for any of the above controls. One thing I absolutely must be able to change is the instructions' units. It currently outputs in imperial/English/us units but I need to be able to toggle to metric for some customers. How can I do this?
Thanks in advance,
Tony
The documentation for mapbox-directions.js can be found in the API.md file in the repo. Keep in mind that this plugin is very much still in development and changes often (it is pre-1.0).
You are right about unit control -- it was added after the release of 0.3.0 so it does not appear in the library in the CDN right now. One of the directions team developers just told me that there will be a new release of mapbox-directions.js tomorrow (yay!) and unit control will be included!
In terms of the inputs control, it doesn't take addresses/POIs, but lat/lon pairs. In the example, you have to click on the map to set a start location and then click on it again to set a destination location. The control will automatically populate with the lat/lon pairs and return a list of directions between them.
Try: L.mapbox.directions({units: 'metric'}); I also couldn't find any documentation but looked at the repo and immediately found this push request from juni 13th.

Determining highway direction

I was wondering if there is a way to get the highway direction of the route.
To be more specific, I am interested in routes on interstate highways in the United States only.
I'll give an example:
Interstate I45 is a north-south highway. When the route is returned, is there a way to know which "direction lane" the route is on?
The problem I'm trying to solve is accessing the rest ares like the one shown on the image here. As you can see, these are two rest areas, each accessible from one direction of the highway.
I would like to display only those accessible from the direction the user is on. I have all the data needed, including if the rest area is on the North/South/East/West direction and I only need the highway direction the route is on.
For obvious reasons, I would like to avoid manually checking if the route just appears to be going northwards.
I checked if this is possible via graphhopper, but it only gives the highway name, without direction. Is it possible to achieve this via Skobbler?
If you are using the TTS instructions (text-to-speech) then in the advice instructions & audio advices you will also receive the "orientation" (coded as a $orientation in the audio config files) - indicating the direction you are driving on a particular highway (south/north, etc.).
The trickier part is that you would have to parse the text instruction to get this information as it's not returned in a separate field (let me know in a comment if this was helpful).
I do not fully understand the original problem but as GraphHopper also returns the geometry for every instruction you should be able to calculate the orientation roughly but easily.
Another more complex approach would be to have a predefined name set associated with the geometry and use the map matching component to find out which highway parts are used in a route.
For obvious reasons,
which obvious reasons? That it is not really going norht south?
Or if something is not possible you always can modify in the code as it is open source or provide a pull request to merge it into the public release (if useful for others) and make it available for the Directions API too.
According to the OSM wiki page Highway Directions In The United States, directions of ways are supposed to be modeled as relation membership roles.
For example, I 75 way 173483918 is a member of the relation 332618 named "I 75 (TN northbound)" with role=north, so it's direction is "north".
The opposite way 173483897 is a member of the relation 332624 named "I 75 (TN southbound)" as role "south".
See more details on the wiki page. Don't know how well established that tagging scheme is, also don't know about router support (Telenav (Scout) seem to be involved in this who now own Skobbler).

Getting distance between 2 markers

I would like to get the distance between 2 markers but not as a direct line, more as a real path like it goes in this plugin -
https://github.com/perliedman/leaflet-routing-machine
I didn't find anything about using this plugin in the directive: angular-leaflet-directive,
if someone can guide how to make it done, it would be very appreciated.
thanks!
I am not sure if you specifically want to use leaflet routing machine to get distances... but if you do, maybe this info can get you started:
Set up a route on your map based on this example by the leaflet routing machine author:
https://www.liedman.net/leaflet-routing-machine/tutorials/interaction/
If you look at that example, there is an array called routes. Each route has some basic statistics associated with it, generated by OSRM. You can pull them by calling for example:
routes[0].summary.totalDistance
or
routes[0].summary.totalTime
Then you can do whatever you want with them. If you dig through the code on GitHub you can see more about how the data are moved around within the plugin and why the array is arranged that way:
https://unpkg.com/leaflet-routing-machine#3.2.12/dist/leaflet-routing-machine.js