Show Specific country and Hide other countries from Map

Balasaheb Molawade 136 Reputation points
2024-06-26T10:03:32.4033333+00:00

Hi,

We are using the Bing Maps API to display the map and plot pushpins. We received a requirement from a customer to display only Germany country on the map and hide all other countries.

Is it possible to achieve this using the Bing Maps API?

Looking forward to your reply.

Thanks!

Azure Maps
Azure Maps
An Azure service that provides geospatial APIs to add maps, spatial analytics, and mobility solutions to apps.
736 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. rbrundritt 18,686 Reputation points Microsoft Employee
    2024-06-26T16:35:57.3066667+00:00

    The only way to achieve something like this would be to create a polygon mask which covers the globe but has a cutout for the boundary of Germany. By default the vector labels will still appear outside of Germany since they are rendered in a separate canvas above polygons. I create a sample and stored the mask polygon as GeoJSON. You can try the sample out here: https://rbrundritt.azurewebsites.net/Demos/BingMaps/GermanyMask/

    You can download the polygon mask GeoJSON file I used here (note that it isn't super high resolution): https://rbrundritt.azurewebsites.net/Demos/BingMaps/GermanyMask/GermanyMaskPolygon.json

    If you want the polygon to appear above the labels, you can put the map into lite mode. This will disable vector labels and labels will instead be static and a part of the base map tiles. This would clip labels at the edge of the boundary though and all shapes will be rendered above the labels which may not be ideal, however this also has an added performance boost. I have a modified version of the sample doing this here: https://rbrundritt.azurewebsites.net/Demos/BingMaps/GermanyMask/lite.html

    Note, in case you missed it, Bing Maps is retiring: https://www.microsoft.com/en-us/maps/bing-maps You can find examples for polygon masks in Azure Maps here: https://samples.azuremaps.com/?search=mask In Azure Maps you can have the polygon mask render above labels.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.