ThinkGeo.com    |     Documentation    |     Premium Support

Connect to WMS maps for web app

Is it possible to connect to WMS compliant maps as part of using UI controls.
I would like to use UI controls and wms maps from different location e.g.
http://mapy.geoportal.gov.pl/wss/service/img/guest/ORTO/MapServer/WMSServer.

  1. Which solution from ThinkGeo is for this?
  2. Where can I configure it?

Thanks for answers

Hi Poul,

it’s possible to access the provided WMS service with ThinkGeo Blazor UI control, with few changes of “Blazor Sample OGC Service Sample”. Here are the demo codes of MapView:

<MapView Id="map" @ref="map"
         Center="@(new PointShape(19.41710,51.57224))"
         Zoom="15"
         MapUnit="@ThinkGeo.Core.GeographyUnit.DecimalDegree"><OverlaysSetting>
        <WmsTileOverlay Id="WmsOverlay" Parameters="@parameters"
                        ServerUris="@serverUris"
                        TileHeight="512" TileWidth="512"></WmsTileOverlay>
    </OverlaysSetting>
    <MapToolsSetting>
        <MapTools>
            <ZoomBarMapTool />
        </MapTools>
    </MapToolsSetting>
</MapView>

@code {
    MapView map;
    Collection<Uri> serverUris = new Collection<Uri> { new Uri("http://mapy.geoportal.gov.pl/wss/service/img/guest/ORTO/MapServer/WMSServer") };
    Dictionary<string, string> parameters = new Dictionary<string, string>
{
        { "layers", "Raster"},
        { "STYLE", "default"},
        { "CRS","EPSG:4326"}
    };
}

Now it should work, but after the map is loaded, it shows the blank map with following error:

Access to image at 'http://mapy.geoportal.gov.pl/wss/service/img/guest/ORTO/MapServer/WMSServer?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&FORMAT=image%2Fpng&TRANSPARENT=true&layers=Raster&STYLE=default&CRS=EPSG%3A4326&WIDTH=512&HEIGHT=512&STYLES=&BBOX=51.56982421875%2C19.40185546875%2C51.591796875%2C19.423828125' from origin 'http://localhost:64632' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Even enabled “crossOrigin:‘anonymous’” to allow “Crossing Domain Access”, still got the same error, could you please help check if the service supports “Access-Control-Allow-Origin”? If yes, we can check if any issues on my side. Sorry for the inconvenience.

If we paste the request URL of one tile, such as http://mapy.geoportal.gov.pl/wss/service/img/guest/ORTO/MapServer/WMSServer?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&FORMAT=image%2Fpng&TRANSPARENT=true&layers=Raster&STYLE=default&CRS=EPSG%3A4326&WIDTH=512&HEIGHT=512&STYLES=&BBOX=51.56982421875%2C19.40185546875%2C51.591796875%2C19.423828125, a satellite image should show up in the browser, it’s proved the codes above is correct, the only problem is “Access-Control-Allow-Origin”. Here is the URL of this WMS service capabilities http://mapy.geoportal.gov.pl/wss/service/img/guest/ORTO/MapServer/WMSServer?request=GetCapabilities&version=1.3.0&SERVICE=WMS.

Thanks,
Johnny

Thanks for the answer, I was looking for a solution all Saturday but it doesn’t work.

a) I have implemented CORS in ThinkGeo.UI.Blazor.HowDol but doesn’t work.

  1. Startup class
    readonly string MyAllowSpecificOrigins = “_myAllowSpecificOrigins”;
    public void ConfigureServices(IServiceCollection services)
    {
    services.AddCors(options =>
    {
    options.AddPolicy(MyAllowSpecificOrigins,
    builder =>
    {
    builder.AllowAnyOrigin()
    .SetIsOriginAllowed(isOriginAllowed: _ => true) or .AllowAnyOrigin()
    .AllowAnyMethod()
    .AllowAnyHeader();
    });
    });

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{

        app.UseCors(MyAllowSpecificOrigins);

b) maybe soluction is reverse proxy site?

Poul

i found also discussion in this area on

Hi Poul,

It looks your server is changing, I tried to view this link:
http://mapy.geoportal.gov.pl/wss/service/img/guest/ORTO/MapServer/WMSServer?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&FORMAT=image%2Fpng&TRANSPARENT=true&layers=Raster&STYLE=default&CRS=EPSG%3A4326&WIDTH=512&HEIGHT=512&STYLES=&BBOX=51.56982421875%2C19.40185546875%2C51.591796875%2C19.423828125

It return a tile image, but when I try to visit it again after half an hour, it shows exception: Parameter ‘layers’ contains unacceptable layer names.

And I found the LAYERS=Raster is also not accepted by server but the layers=Raster works at the first, by default our parameter is used like LAYERS, could you please double check that?

I will do more test when the server is stable.

Regards,

Ethan