nrenner / brouter-web

Web client for BRouter, a routing engine based on OpenStreetMap
https://brouter.de/brouter-web/
MIT License
364 stars 71 forks source link

Google Street View integration #291

Open thof opened 4 years ago

thof commented 4 years ago

Have you considered adding integration with Google Street View?

I've been using BRouter-web for many years and for me it's the main missing feature I can think of. As majority of European countries are covered in great details in Street View, it could be useful to add it to web interface. I briefly looked at the license and it seems that Google supports non-commercial creative use as stated here https://www.google.com/permissions/geoguidelines/ so at least from the legal perspective it shouldn't be big deal.

Recently I started to look at Street View Static API and today I finished first working version. I have very little experience in JavaScript so I based mainly on existing BR plugins. The user experience are not the best right now as it requires to use control key so it's for desktop users only.

Commit: https://github.com/thof/brouter-web/commit/9a78a6ac0753e9144c9f0264f8d12a973cb95f20 Demo: https://rara.ovh/brouter-web

How to use:

  1. Press and hold the control key and cursor will change to pointer.
  2. While holding, click on the desired road (it will serve as location for Street View panorama).
  3. Again while holding the key, click on another point on the same road (it will serve as heading direction of the camera).
  4. The closest panorama image will appear in the bottom left corner.
  5. Now you without releasing control key you can click further on roads so the point picked in 3. will server as location and a new click as heading of the camera etc.
  6. Once you release the control key you can delete image layer by just clicking on the image layer.

What do you think?

nrenner commented 4 years ago

Thanks for the suggestion!

Unfortunately using Google APIs like Street View on non-Google maps actually is violating their Google Maps Platform Terms of Service (what you are linking to are the end user terms):

(e) No Use With Non-Google Maps. To avoid quality issues and/or brand confusion, Customer will not use the Google Maps Core Services with or near a non-Google Map in a Customer Application. For example, Customer will not (i) display or use Places content on a non-Google map, (ii) display Street View imagery and non-Google maps on the same screen, or (iii) link a Google Map to non-Google Maps content or a non-Google map.

I would prefer integrating non-Google services anyway, e.g. Mapillary, see #153.

What I already have in mind and what we could do, is to have a link or button to open external services in a new window with the same map view, like you can already do for the current map with the link in the lower right corner, e.g. see the optional "Mapillary Coverage" overlay. But of course that is not the same as having it integrated.

thof commented 4 years ago

Thanks for your feedback and making it clear from legal perspective. That's a shame...

I like Mapillary but unfortunately its coverage is rather low comparing StreetView and it isn't open source as well so BRouter is tainted anyway :)

I think there could be another way to avoid violating Google Maps Platform Terms of Service (though please bear in mind that I'm very new to OSM, Leaflet etc. so I don't know if it's doable). There is a plugin called Leaflet.GridLayer.GoogleMutant claiming that:

GoogleMutant is meant to provide a reliable (and ToC-compliant) way of loading Google Map's tiles into Leaflet, nothing more.

I see that some people use L.Control.Layers in their applications to switch between OSM and Google Maps layers. Therefore if we would introduce Google Maps as an optional layer to BRouter then we could keep integration with StreetView on this particular layer.

What do you think? Assuming it's feasible, would you accept such pull request?

nrenner commented 4 years ago

Not sure. I'm very reluctant to add anything Google, not just because it's not open, but because Google.

Showing Street View only with a GoogleMutant layer would be Ok with the terms I think.

Some further doubts and potential issues:

(iii) link a Google Map to non-Google Maps content

Not sure how to interpret the terms in general and the meaning of "link" (associate or HTML-link) here, but this could also mean not showing an OSM-derived route on a Google map?

Using GoogleMutant requires to load the Google Maps JavaScript API to show maps, as Google terms do not allow direct tile access. Don't know if it's possible to only load that if the layer is activated. Such synchronizing of two map libraries also might have some issues. On the plus side, you could then probably just as well use the full interactive Street View.

Google Maps only allows free use up to a certain limit, see pricing. I want to lookup some of our usage numbers anyway, so I can make a better guess where we would land there.

thof commented 4 years ago

Not sure. I'm very reluctant to add anything Google, not just because it's not open, but because Google.

I can understand your aversion but sometimes benefits outweigh potential (moral) damages.

Not sure how to interpret the terms in general and the meaning of "link" (associate or HTML-link) here, but this could also mean not showing an OSM-derived route on a Google map?

It's hard to say. The interpretation can be very wide I guess. But for some reason GoogleMutant is an active project for many years and it was meant to use Leaflet primitives in Google Maps.

Don't know if it's possible to only load that if the layer is activated. Such synchronizing of two map libraries also might have some issues. On the plus side, you could then probably just as well use the full interactive Street View.

Yes, I hope we can load these libs dynamically but I'm not sure about full Street View since the project mentions only "basemaps".

Google Maps only allows free use up to a certain limit, see pricing.

For now I was thinking it would be enough to ask user to provide his own API key since anyone can get $200 free monthly usage and that's a lot for single user.

Anyway it seems I'll find some time during the weekend to play around with GoogleMutant. Let's see how far I can get.

nrenner commented 4 years ago

Yes, I hope we can load these libs dynamically but I'm not sure about full Street View since the project mentions only "basemaps".

GoogleMutant itself might not support it, but it requires the Google Maps JavaScript API (streetview) that does.

Don't know how that would work together with the plugin and Leaflet though, just found this issue: StreetView Pegman (#57) · Leaflet.GridLayer.GoogleMutant

nrenner commented 4 years ago

For now I was thinking it would be enough to ask user to provide his own API key since anyone can get $200 free monthly usage and that's a lot for single user.

This would be cheating and I will not support that on our site. API keys are clearly meant per developer / per site and not for end users.

Don't know if they do, but if I were a service provider I would block any site that sends multiple keys with the same referrer header.

Some example pricing calculation:

With these assumptions:

That would still be free, but already close, and given that our route request numbers doubled since then, we would be above the free credit.

So I'm afraid, but I think alone because of this we cannot integrate any Google services. Should we ever introduce a pro version with a paid subscription, this could maybe be reconsidered.

thof commented 4 years ago

Don't know how that would work together with the plugin and Leaflet though, just found this issue: StreetView Pegman (#57) · Leaflet.GridLayer.GoogleMutant

It just generates non-interactive StreetView Pegman and that's pretty much all. I think that full interactive Street View is not possible with GoogleMutant. It seems that introducing full-featured Street View is, more or less, like implementing new application that is capable to utilize both Leaflet and Google Maps API and can switch between them.

This would be cheating and I will not support that on our site. API keys are clearly meant per developer / per site and not for end users.

Ok, I get your point.

That would still be free, but already close, and given that our route request numbers doubled since then, we would be above the free credit.

We can set quotas on APIs so once the users reach the limit, it will just stop work.

Anyway I almost finished the next version of my plugin. I need to deploy it so you can see how it's done.

thof commented 4 years ago

I've pushed some new changes to the repo. Here is the diff https://github.com/nrenner/brouter-web/compare/master...thof:master?diff=split

Again a live preview is available at https://rara.ovh/brouter-web

I've changed the default behavior a bit. Once the "Google Maps (roadmap)" layer is added from "More" tree, it doesn't need to be activated explicitly. It's enough, using any base layer, to hold Control key and start clicking to make Google Maps layer active. Once the Control key is released it will switch back to the original base layer and remove Street View image. I think it's a rather convenient way to take a quick peek at the road's condition.