digidem / leaflet-bing-layer

Bing Maps Layer for Leaflet v1.0.0
http://digidem.github.io/leaflet-bing-layer/
87 stars 53 forks source link

Bing Maps getCredentials for non-billable session ID #16

Open ARChilton opened 7 years ago

ARChilton commented 7 years ago

Does anyone have any methodology for requesting the bing maps session ID used after the original API key to reduce billable map tile requests.

On the Bing site it says this:

Reducing Usage Transactions If you are using the Bing Maps Rest services in conjunction with one of the Bing Maps map controls, you can significantly reduce the number of transactions your application incurs against your Bing Maps account if you request the Bing Maps key from the map control rather than using your normal Bing Maps key. This is quite often an overlooked feature. When getting the credentials from the map you do not get back your original Bing Maps key. Instead, you get a special session key which you can use as a Bing Maps key to make requests of the Bing Maps services. By doing this, all transactions incurred by this session key will be non-billable. https://msdn.microsoft.com/en-us/library/dn894107.aspx

However, I cannot work out how to do this using Leaflet and this plug-in (which is very good!)

If anyone has any ideas that would be brilliant, thanks!

gmaclennan commented 7 years ago

I believe this is what this plugin already does. It makes an initial request to the Imagery Metadata API with your Bing Maps API Key, which returns a URL for tile requests. This URL does not seem to include your API key and I don't think those tile requests are billable, but I do not know for sure.

gmaclennan commented 7 years ago

I think this is already resolved, closing since it's been quiet for 6 months.

johnd0e commented 5 years ago

I believe this is what this plugin already does.

No, it does not.

I don't think those tile requests are billable

In fact it is billable. See https://docs.microsoft.com/en-us/bingmaps/getting-started/bing-maps-dev-center-help/understanding-bing-maps-transactions#rest-services

Only RESTImagery-BasicMetadata is not billable, but it does not contain URI template, which is needed for plugin.

And you can see in that table - RESTImagery is billable.

So, every Bing layer instance initialization produces billable request. Even if layer is not added to map.

So it makes sense to defer metadata request until layer is actually added to map. Old shramov plugin does so.

johnd0e commented 5 years ago

BTW, your POINT_METADATA_URL could be made with not billable BasicMetadata request, you just need to fix url.

gmaclennan commented 5 years ago

Re-opening, open to PRs to fix this.

johnd0e commented 5 years ago

open to PRs to fix this.

Implemented in other project: https://github.com/shramov/leaflet-plugins/blob/61a19e577fc244e0c00b278bea886e09edbc7d21/layer/tile/Bing.js#L212-L216

And https://github.com/shramov/leaflet-plugins/blob/61a19e577fc244e0c00b278bea886e09edbc7d21/layer/tile/Bing.js#L150