Ceemie

web adf map control not refreshing and displaying results but TOC will

Discussion created by Ceemie on Nov 25, 2013
Latest reply on Dec 5, 2013 by brenth
I'm using ESRI ArcServer 10.0 and Visual Studio 2010 c#.NET.

We've done a spatial query using ArcObjects and are now trying to load the results from an ifeatureclass or igeofeature to the MapResrouceManager. When we do this we can sometimes get the TOC to display the one .sde shapefile and layer name "Results". but we can never see the layers in the map. See attached word document for pictures.

// Display FeatureClass in ArcServer Map1      
            if (!MapResourceManager1.Initialized)
            {
                MapResourceManager1.Initialize();
            }

            ESRI.ArcGIS.ADF.Web.UI.WebControls.Map pMap1 = (ESRI.ArcGIS.ADF.Web.UI.WebControls.Map)Page.FindControl("Map1");
            ESRI.ArcGIS.ADF.Web.UI.WebControls.Map mapctrl = (ESRI.ArcGIS.ADF.Web.UI.WebControls.Map) pMap1;
            ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapFunctionality mf = (ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapFunctionality)mapctrl.GetFunctionality(0);

            ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapResourceLocal mapres = (ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapResourceLocal)mf.MapResource;


            ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapResourceLocal mrl = (ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapResourceLocal)MapResourceManager1.GetResource(0);
            IServerContext iServerContext = mapres.ServerContextInfo.ServerContext;
            ESRI.ArcGIS.Carto.IMapServer2 pMapServer = iServerContext.ServerObject as ESRI.ArcGIS.Carto.IMapServer2;
            ESRI.ArcGIS.Carto.IMapServerObjects2 pMapServerObjects = pMapServer as ESRI.ArcGIS.Carto.IMapServerObjects2;
            ESRI.ArcGIS.Carto.IMap pMap = pMapServerObjects.get_Map(pMapServer.DefaultMapName);


            IMapServer ms = (IMapServer)mrl.ServerContextInfo.ServerContext.ServerObject; //(IMapServer)GetServerContext().ServerObject;//
            IMapServerObjects2 mso = (IMapServerObjects2)ms;
            //***IMap map = mso.get_Map(ms.DefaultMapName);
            IFeatureLayer pFeatureLayer = (IFeatureLayer)mrl.ServerContextInfo.ServerContext.CreateObject("esriCarto.FeatureLayer"); //new FeatureLayerClass();
            IGeoFeatureLayer geoLayer = (IGeoFeatureLayer)pFeatureLayer;
           
           
           // pFeatureLayer.FeatureClass = pResultsFeatureClass; //pFeatureWorkspace.OpenFeatureClass("GRIDSDE2.DBO.SMCBoundary");//
            pFeatureLayer.FeatureClass = pResultsFeatureClass2;
           


            pFeatureLayer.Name = "Results";
          
            //IGeoFeatureLayer geoLayer = (IGeoFeatureLayer)pFeatureLayer;
            IFeatureRenderer renderer = geoLayer.Renderer;
            ISimpleRenderer simpleRenderer = (ISimpleRenderer)renderer;
            IRgbColor pRgbColor = new RgbColorClass();
            pRgbColor.Red = 0;
            pRgbColor.Green = 0;
            pRgbColor.Blue = 210;

            ESRI.ArcGIS.Geometry.esriGeometryType geometryType = pFeatureLayer.FeatureClass.ShapeType;
            if (geometryType == ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint)
            {
                ISimpleMarkerSymbol simpleMarkerSymbol = (ISimpleMarkerSymbol)simpleRenderer.Symbol;
                simpleMarkerSymbol.Color = (IColor)pRgbColor;
            }
            else if (geometryType == ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline)
            {
                ISimpleLineSymbol simpleLineSymbol = (ISimpleLineSymbol)simpleRenderer.Symbol;
                simpleLineSymbol.Color = (IColor)pRgbColor;
            }
            else if (geometryType == ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon)
            {
                ISimpleFillSymbol simpleFillSymbol = (ISimpleFillSymbol)simpleRenderer.Symbol;
                simpleFillSymbol.Color = (IColor)pRgbColor;
            }
            else
            {
                throw new Exception("No renderer or symbol selected.  Shape type undetermined.");
            }

            pMapServerObjects.get_Map(pMapServer.DefaultMapName).AddLayer(pFeatureLayer);
            //pMap.AddLayer(pFeatureLayer);
           //*** map.AddLayer(pFeatureLayer);
            int test = pMap.LayerCount;
            ESRI.ArcGIS.Carto.IActiveView pactiveview = (ESRI.ArcGIS.Carto.IActiveView)pMap;
            pactiveview.Refresh();
           
            //pMap.ActiveGraphicsLayer., null, null);
             mso.RefreshServerObjects();
             pMapServerObjects.RefreshServerObjects();  //
             //
             //mapres.RefreshServerObjects();
             Map1.RefreshResource(mf.Resource.Name);
             Session["addedlayersid"] = mso.get_LayerID(ms.DefaultMapName, pFeatureLayer);
             mapres.RefreshServerObjects();
               // mapctrl.RefreshResource(mf.Resource.Name);
               //mapctrl.RefreshResource(mapres.Name);
               //mapctrl.RefreshResource(mrl.Name);
             Toc1.Refresh();
             Map1.CallbackResults.CopyFrom(Toc1.CallbackResults);
            
             Map1.Refresh();
             Map1.Reset();
             Map1.Rotation = 45;
            
             //Map1.Refresh();
             //mapctrl.Refresh();
            pAoInitialize.Shutdown();
            mapres.Dispose();
            mf.Dispose();
            Toc1.Dispose();
            Map1.Dispose();
           
        }

Attachments

Outcomes