ThinkGeo.com    |     Documentation    |     Premium Support

WmsRasterLayer being static

Hello everyone,


I'm using a WmsRasterLayer in my application but I've got an issue when I try to pan or to zoom on the map.

This is my method to initialize the layer :


public void AddWMSLayer(BackgroundLayer backgroundWMS)
{
this.MapUnit = GeographyUnit.Meter;

try
{

WmsRasterLayer worldLayer = new WmsRasterLayer();
worldLayer.Uri = new Uri(backgroundWMS.urlValue);

worldLayer.UpperThreshold = double.MaxValue;
worldLayer.LowerThreshold = 0;

worldLayer.TimeoutInSecond = 60;

worldLayer.Exceptions = "Application/VND.OGC.SE_XML";

#region Passage des parametres
worldLayer.Parameters["REQUEST"] = backgroundWMS.request;
worldLayer.Parameters["OUTPUTFORMAT"] = backgroundWMS.outPutFormat;
worldLayer.Parameters["SERVICE"] = backgroundWMS.serviceOGC;
worldLayer.Parameters["STYLES"] = backgroundWMS.stylesLayers;
worldLayer.Parameters["SRS"] = "EPSG:" + backgroundWMS.projValue;
//Ajout du layer
worldLayer.ActiveLayerNames.Add(backgroundWMS.layers);

//If I can't add these parameters, the layer doesn't work 
worldLayer.Parameters["BBOX"] = "550000,60000,660000,140000";
worldLayer.Parameters["WIDTH"] = "800";
worldLayer.Parameters["HEIGHT"] = "582"; 
#endregion


GoogleMapZoomLevelSet zoomLevelSet = new GoogleMapZoomLevelSet();
zoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
this.ZoomLevelSet = zoomLevelSet;

AddStaticLayer(backgroundWMS.name, worldLayer);

}
catch (Exception ex)
{
GeosysLog.Error(ex);
throw new StaticLayerException(32310, string.Format(ResXManager.GetResourceString("mappingWMSError"), backgroundWMS.urlValue), ex);
}
}

If I don't add the BBOX, WIDTH and HEIGHT parameters, the layer isn't displayed. If I add them, the layer is displayed but it's static.

When I zoom, only the feature changes. Same thing when I pan the map, only the feature moves. The WMS layer doen't move or zoom.


Do you have any idea about that issue ?


Thanks by advance.



Hi Pierre-Antoine, 
  
 Thanks for your post.  
  
 If you hard coded the prameters BBox,Wdith and height, you will always get the static image, because the client side requires the same extent image everytime. I think that make sence. I didn’t see anything unusual in your code pasted above, but it  will help a lot if you can upload the WMS server side code or a sample to recreate this issue. 
  
 Thanks, 
 Lee

Hi Lee,


You can find in the attachement a project with my issue.


Thanks by advance.



CartoTestWMS.zip (15 KB)

Hi Pierre-Antoine, 
  
 It looks the problem still be the extent incorrcet caused by projection. So the code as below should works. 
  
  
 
private void btWithParameters_Click(object sender, EventArgs e)
        {
            AddLog("");
            AddLog("Loading with parameters START");
            map.Overlays.Clear();
            map.MapUnit = GeographyUnit.Meter;

            try
            {
                WmsRasterLayer worldLayer = new WmsRasterLayer();
                worldLayer.Uri = new Uri("wms.geo.admin.ch/");

                worldLayer.UpperThreshold = double.MaxValue;
                worldLayer.LowerThreshold = 0;

                worldLayer.TimeoutInSecond = 60;

                worldLayer.Exceptions = "Application/VND.OGC.SE_XML";

                worldLayer.Parameters["REQUEST"] = "GetMap";
                worldLayer.Parameters["OUTPUTFORMAT"] = "image/png";
                worldLayer.Parameters["SERVICE"] = "WMS";
                worldLayer.Parameters["STYLES"] = "default";
                worldLayer.Parameters["SRS"] = "EPSG:21781";

                worldLayer.ActiveLayerNames.Add("ch.blw.ursprungsbezeichnungen-spirituosen-eau_vie_poire");

                //worldLayer.Parameters["BBOX"] = "550000,60000,660000,140000";

                worldLayer.Parameters["WIDTH"] = map.Width.ToString();
                worldLayer.Parameters["HEIGHT"] = map.Height.ToString();

                GoogleMapZoomLevelSet zoomLevelSet = new GoogleMapZoomLevelSet();
                zoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
                map.ZoomLevelSet = zoomLevelSet;

                if (worldLayer.HasBoundingBox)
                {
                    worldLayer.Open();
                    
                    ManagedProj4Projection proj4 = new ManagedProj4Projection();
                    proj4.InternalProjectionParameters = ManagedProj4Projection.GetDecimalDegreesParametersString();
                    proj4.ExternalProjectionParameters = ManagedProj4Projection.GetEpsgParameters(21781);
                    proj4.Open();
                    map.CurrentExtent = proj4.ConvertToExternalProjection(worldLayer.GetBoundingBox());
                    AddLog("Bbox : " + map.CurrentExtent.GetWellKnownText());
                    worldLayer.Close();
                }

                LayerOverlay staticOverlay = new LayerOverlay();

                staticOverlay.Layers.Add("WMS", worldLayer);
                map.Overlays.Add("WMS", staticOverlay);

                map.Refresh();
                AddLog("Loading with parameters END");

            }
            catch (Exception ex)
            {
                AddLog("ERROR : " + ex.Message);
            }
        }