Is it possible to convert a (Leaflet) route into a polyline? - leaflet

I'm currently making a map with roads that I have driven in the past. Right now, for one route I enter a few waypoints, and the route is calculated through these waypoints using OSRM.
It works fine, but the problem is that on every pageload this route will be recalculated (which makes sense, cause that's how routing works). Let's say I have 50 routes, that'll be a lot of requests. However, I want to be able to calculate the route once, and save the line that is generated as a polyline, which essentially caches the route forever.
Since the routes all stay the same, and no recalculation is necessary, this would be the best way, because then I don't need to setup my own OSRM server or pay for a routing service. (I might need to recalculate routes every once in a while, but that's alright).
Is this way of converting/cachine routes possible? It would be great if I could get this project working live without any routing attached to it.
Thanks for your help in advance!

Related

How to get agents to follow GIS Route created on-the-fly

I'm currently working on a model where agents move to random points in the ocean on a GIS map. I have managed to write code (with constraints mentioned in my previous post) that often create non-straight GIS Routes between the agent's location and the random point on the GIS map, by building an array of GISMarkupSegments, and calling the new GISRoute(this.map, segments) constructor. However, even after constructing this route, the agents do not follow the route. I have read all the relevant documentation and I'm still quite confused on how to get the agents to follow this programmatically constructed GIS route:
At first, I thought I would only need to create the GIS route, and the agent could automatically use it if it's on top of the starting point of the route, but it doesn't seem to find this route, as it throws an error when I turn on "show error dialog" in the map routing settings, meaning it cannot find this route I just created.
Then, I thought I would have to add all the routes to a GIS network and have the agents move along this network, but this doesn't seem to work since the network will need to constantly be added to over time, and once a network is initialized, I can't add any more GIS routes to it.
I think my question boils down to how AnyLogic implements the "create straight route" option under the Routing setting if route is not found for a GIS map, so I can recreate that for my own custom GIS route for agents to take on the fly. i.e. how do I make it so that my agents actually take the GIS route I just created?

Is there a way for a service worker to know the url of the requesting page?

I'm converting my large legacy application to a PWA and finding that many things don't work, because they were designed with very different assumptions about caching, state, etc. I want to convert the whole site eventually, but I'd like to restrict the scope of the service worker to specific pages, so that I can convert them one by one.
I know that you can limit service worker scope to a sub-directory by placing the service worker in that sub-directory, but that doesn't map well to the order in which I need to do the conversion. I would prefer to have the service worker in the root directory, but implement a whitelist of pages that I want it to handle, until such time as all pages are converted and I can remove the restriction.
Within a service worker, is there a way to access the url of the referring/current page, so that I could check to see if it's on the whitelist and allow the fetch, and if not just return?
Or is there a better way to handle this situation?
It turns out that FetchEvent.request has a referrer property, which is exactly what I needed. Not sure how I missed this.

Can traffic conditions be ignored when generating directions in bing maps web control API?

For our application we are presenting route options to a user that will be used for planning purposes (distance, time, etc). Is there a way, with the bing maps web control api, to ignore traffic conditions? For example, if a major highway is closed at the time the directions are generated, I don't want to route around that. Other conditions are fine, such as highway or non-highway, or possibly just other options that are similar. But we don't want to change the route options based on current traffic. Thanks.
Simply set the routeOptimization option in the directionsRequestOptions to shortestTime. I believe that is the default. The calculated route will be based on posted speed limits and not on traffic conditions. The response includes two times, one with and one without traffic for the route path.

Routing using OSRM for multiple profiles - does profile in the URL actually do anything?

With ORSM there are 3 profiles for different modes of transport, cycle, foot and car. These come with OSRM.
According to the following post which was made 1 year ago, OSRM does not support multiple profiles:
OSM routing (OSRM): do I need to duplicate all data for different profiles?
Yet in the official documentation there is a profile argument as part of the URL called for retrieving a route from a running OSRM instance:
http://project-osrm.org/docs/v5.6.4/api/#general-options
The path would look something like this:
http://router.project-osrm.org/route/v1/driving/
Without driving, foot or cycle in the URL a route won't be retrieved so one of them is required for the API, yet if I compile a route for car on the server, but then use /foot/ in the URL to retrieve a route, it will still retrieve a car based route, completely ignoring 'foot'.
Could anybody from OSRM explain why something as useful as multiple profile support has been withdrawn, and what the point of driving is in the above URL seeing as it is ignored anyway and just appears to use the profile attached to the running instance of OSRM?
The solution to the problem of multiple profiles appears to be to host parallel copies of the routing machine for each profile and address different IP's, so again, what is the point of 'profile' in the URL?
Could anybody from OSRM explain why something as useful as multiple profile support has been withdrawn
The support has never been there. You will need to run separate osrm instances for each profile.
The URL option is merely there to make it easier to stick a nginx in front of your OSRM instances and distribute to the correct instance based on profile string.
We might implement multiple profiles in the same OSRM instance in the future, but this is still far out.

Tornado redirect to a different domain

I have a Tornado server and I want to redirect people coming from a certain country to a totally different domain. It depends on their IP, and I need it to work for every URI chosen. So for example if someone goes to www.mysite.com/about from a British IP, I want to redirect her to www.mysite.uk/about.
I tried adding the function initialize() to the BaseHandler, but according to what I've seen, It's impossible to finish from the init.
I checked out RedirectHandler, but it changes only the URI, and not the entire domain as I need.
Do you know of any solution within Tornado? (I also use nginx, but don't think it can support checking the ip, finding the locations, and also I have a lot of URIs).
Thank you!
RedirectHandler works with both absolute and relative urls; why do you think you can't change the domain with it?
You cannot redirect (or send any response) from initialize(), but you can from prepare(). It sounds like this is the right place for what you want to do:
def prepare(self):
if should_redirect(self.request):
self.redirect(new_domain, self.request.uri)
raise tornado.web.Finish()