Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Add QMS Bing Maps #4150

Merged
merged 2 commits into from
Feb 7, 2024
Merged

[Feature] Add QMS Bing Maps #4150

merged 2 commits into from
Feb 7, 2024

Conversation

mind84
Copy link
Contributor

@mind84 mind84 commented Feb 2, 2024

TL;DR

Enabling Bing Maps to be loaded as baselayers in LWC through OpenLayers dedicated implementation by importing Bing Maps in QGIS project from QuickMapServices QGIS Plugin

DETAILS

In previous versions of LWC (i.e. 3.6) it was possible to add a defined set of external layers (including Bing) by flagging the corresponding option in the plugin's base-layer panel and without adding any layer to the project. Then the plugin updates the cfg accordingly by setting the corresponding properties in the option section of the cfg:

"options": {


        "osmMapnik": "True",
        "openTopoMap": true,
        "bingKey": "some___key",
        "bingStreets": "True",
        "bingSatellite": "True",

}

Now, since the direction is to rely on the QGIS project, in newer versions this panel has become deprecated and the above properties that defines these external layers are no longer written in cfg file.
Furthermore, following the update of the OpenLayers library, some of this external layers are not longer supported (e.g. Google Maps) by the lib itself.

In the "Bing" specific case, the current version of OpenLayers offers supports for rendering Bing tiles.

This implementation allows LWC to recognize the QMS Bing Maps from QGIS project, read the corresponding Bing Api Key from the cfg and instantiate with these options the Bing OpenLayers class

NOTES

  • This functionality relies for now on the external url assigned to the layer by QMS when it is added on QGIS project. This url is set in the url property of the externalAccess object in the cfg response.

  • I guess this object was only kept for backwards compatibility since the properties listed are no longer written to the cfg file.

  • I've extended this default configuration with a new QMSExternalLayer object, to keep things clearly separated (and hopefully maintainable).

  • urls of Bing maps currently supported:

    • Bing Map, alias bing-road in the LWC < 3.7 configuration. url = https://ecn.dynamic.t0.tiles.virtualearth.net/comp/CompositionHandler/{q}?mkt=en-us&it=G,VE,BX,L,LA&shading=hill
    • Bing Satellite, alias bing-aerial in the LWC < 3.7 configuration. url = https://ecn.t3.tiles.virtualearth.net/tiles/a{q}.jpeg?g=0&dir=dir_n.

You can check this functionality in the bing_basemap.qgs project included in this PR.

Thanks

Related to #4030

Funded by Faunalia

@github-actions github-actions bot added this to the 3.8.0 milestone Feb 2, 2024
@Gustry Gustry added sponsored development This development has been funded javascript Pull requests that update Javascript code backport release_3_7 labels Feb 2, 2024
@Gustry
Copy link
Member

Gustry commented Feb 2, 2024

Thanks for tackling this !
I will let others commenting about the technical part. I thought some work was done about these layers.

Just a note for now :

This functionality relies for now on the default layer name assigned by QMS when it is added on QGIS project, so to get it work the layer name should not be changed (I'm not sure how limiting this might be)

Default names of Bing maps currently supported:

This is fragile and will be broken IMHO. (or a dev in the plugin must be done, but I don't think it's the way to go)

In the QGS file of your PR :

<layer-tree-layer source="type=xyz&amp;zmin=1&amp;zmax=18&amp;url=https://ecn.t3.tiles.virtualearth.net/tiles/a{q}.jpeg?g%3D0%26dir%3Ddir_n'" checked="Qt::Checked" patch_size="-1,-1" name="Bing Satellite" providerKey="wms" legend_exp="" expanded="1" legend_split_behavior="0" id="Bing_Satellite_9ceaa33e_9c61_4fd0_b607_68ffd5614d88">

QGIS is checking if the {q} is in the datasource : https://github.com/qgis/QGIS/blob/61fe17774e1eae721b6a616a2bbe934ca399a6ca/src/providers/wms/qgswmsprovider.cpp#L1679
if we want less fragile, we could check the URL is virtualearth.net ?

@mind84
Copy link
Contributor Author

mind84 commented Feb 2, 2024

This is fragile and will be broken IMHO. (or a dev in the plugin must be done, but I don't think it's the way to go)

I agree with you and I think this is the most tricky part. Indeed, this is the main reason I've created a draft :)

if we want less fragile, we could check the URL is virtualearth.net ?

Thanks for checking this! Surely the url is much more stable than the default name. I will try with this solution but I think that probably it requires some server side implementation.

Thanks

@mind84
Copy link
Contributor Author

mind84 commented Feb 5, 2024

@Gustry,

I've changed the logic using the url instead of the name. It's a little tricky because I've not found a very strong way to separate roads from satellite map type using just the url.
I don't know if this result would be solid enough/acceptable. This way, however, users will gain more flexibility on the layer name and will be able to change it in QGIS project.

@mind84 mind84 marked this pull request as ready for review February 6, 2024 13:36
@Gustry Gustry added the run end2end If the PR must run end2end tests or not label Feb 6, 2024
Copy link
Member

@Gustry Gustry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM from the user point of view

The URL checks looks better like this.

Copy link
Contributor

@nworr nworr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good PR, thanks for the detailed description.
Only a question about the exposed bing key

Copy link
Member

@Gustry Gustry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is-it a typo ?

tests/js-units/node/state/baselayer.test.js Outdated Show resolved Hide resolved
tests/qgis-projects/tests/bing_basemap.qgs Outdated Show resolved Hide resolved
tests/qgis-projects/tests/bing_basemap.qgs Outdated Show resolved Hide resolved
tests/qgis-projects/tests/bing_basemap.qgs Outdated Show resolved Hide resolved
tests/qgis-projects/tests/bing_basemap.qgs.cfg Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport release_3_7 javascript Pull requests that update Javascript code run end2end If the PR must run end2end tests or not sponsored development This development has been funded
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants