Wms Custom Provider

Hi,

I’m developing a windows form application with c # and I want to use mapwingis custom provider Wms.
I have reviewed your documents, but could not find how to import a wms service.There are some Code samples and I implemented them but I couldn’t provide the image.

Sample Wms Service

and my sample code

and exception

{“Exception of type ‘System.Windows.Forms.AxHost+InvalidActiveXStateException’ was thrown.”}

How can i solve this problem and what is your suggestion.

Thank you

Hello @mcanitez

The exception does not specifically have to do with the WMS layer, but with the OCX. You are instantiating the OCX inline rather than adding it as a control to your main form.

To verify, I pasted your code into an app that does not have the OCX loaded onto the form (in the Designer), and tried to load a JPG, and I get the same exception.

You should remove your declaration of axMap (AxMap axMap = new AxMap();) and instead add the OCX to your form, it will generate an axMap1 variable. You then can add your layers to that map reference, and it should work properly.

Regards,
Jerry.

Thank you for the help.I apply the sample code but I always see the openstreetmap map

sample_Code

I keep getting the same result even though I write different urls.I do not understand how to add custom provider.

Hello @mcanitez

You can add a custom provider via the TileProviders.Add method.

Here’s a simple example that sets Open Street Maps as a custom provider.

// add definition of custom provider
int newID = (int)tkTileProvider.ProviderCustom;
axMap1.Tiles.Providers.Add(newID, "Custom Provider",
    "https://{switch:a,b,c}.tile.openstreetmap.org/{zoom}/{x}/{y}.png",
    tkTileProjection.SphericalMercator, 0, 18);
// set custom provider as the current provider
axMap1.Tiles.ProviderId = newID;
axMap1.Redraw3(tkRedrawType.RedrawSkipAllLayers, true);

Regards,
Jerry.

Addendum: you can find more information here, scrolling down for examples and explanations of custom providers.

Hi,
I realize it’s been a long time. Thank you for the answer. I wrote code as you told.
I just added as much authorization code as I described. I do not know if this method is correct. When I run it in this state, nothing appears on the screen. I got the image with a different component but I want to use mapwingis. I am aware that I am doing something missing. I’m waiting for your help.

[image]

Hello @mcanitez

I really know nothing about WMS layers, but I think it is more likely you should be using the WMSLayer class rather than setting up a custom provider, since I don’t think a WMS server is a Tile Provider. Perhaps someone else has some knowledge in this area? (@pmeems, do you know more about this?)

@jerryfaust is right. You cannot use the Tile provider, which is doing a TMS request to use with WMS.
Those are two different protocols.
The WMS Layer is the way to go.

Thanks for the answer. So how can I solve this. I have reviewed the document but have not found a complete solution. What do I need to do to view custom wms and add authorization. Can you send an example.

I haven’t used the WMS Layer myself and the documentation doesn’t have anything about how to add authorization.

You could also create a GDAL WMS XML file and load it as a layer. I have no experience with this either, but in their documentation I see room for username and password.