Customer Service | Training | Contact Us
You are here: Home > User Forums > arcgis server forums > Thread Replies

ArcGIS Server Forums

ArcGIS Server .Net: Developing applications forum

Trying to dynamically create hidden, query-...   c r b Nov 03, 2009
Re: Trying to dynamically create hidden, qu...   c r b Nov 03, 2009
Re: Trying to dynamically create hidden, qu...   Jamie Petersen Nov 03, 2009
Re: Trying to dynamically create hidden, qu...   c r b Nov 03, 2009
Report Inappropriate Content • Top • Print • Reply    
Subject Trying to dynamically create hidden, query-only map resource 
Author c r b 
Date Nov 03, 2009 
Message We're trying to programmatically create a dynamic MapResourceItem with the .NET ADF (v9.3.1) so that we can query a map service with an IQueryFunctionality, and then dispose of it when we're done. The MapResourceItem needs to have DisplaySettings of 'Visible=False' and 'displayInToc=False'. This history is long and sordid so I won't get into it here but suffice it to say this is an application requirement.

We've gone through several combinations of MapResourceItem properties, methods of adding it to the map's ResourceManager, etc. but have not been able to get a working MapResourceItem with the appropriate functionalities.

Has anyone had success with this? I've browsed some of the other forum postings but none have provided the silver bullet. Some already viewed:
http://forums.esri.com/Thread.asp?c=158&f=2272&t=242909
http://forums.esri.com/Thread.asp?c=158&f=2276&t=214628
http://forums.esri.com/Thread.asp?c=158&f=2276&t=235252

The latest iteration of our code is below. 
 
GISResourceItemDefinition definition = new GISResourceItemDefinition();
definition.DataSourceDefinition = "http://gis5/arcgis/services";
definition.DataSourceType = "ArcGIS Server Internet";
definition.ResourceDefinition = "Layers@onestop/IaFmFacilities";
definition.DataSourceShared = true;
definition.Identity = "";

DisplaySettings displaysettings = new DisplaySettings();
displaysettings.Visible = false;
displaysettings.Transparency = 0;
displaysettings.DisplayInTableOfContents = false;
displaysettings.EnableDynamicTiling = false;
ImageDescriptor imgDesc = new ImageDescriptor();
displaysettings.ImageDescriptor = imgDesc;

MapResourceItem mapResourceItem = new MapResourceItem();
mapResourceItem.Name = "QueryEnvFacs";
mapResourceItem.Parent = MapResourceManager;
mapResourceItem.DisplaySettings = displaysettings;
mapResourceItem.Definition = definition;

//MapResourceManager.ResourceItems.Insert(0, mapResourceItem);

mapResourceItem.InitializeResource();

resource = MapResourceManager.CreateResource(mapResourceItem);

return resource;
 
   
Report Inappropriate Content • Top • Print • Reply    
Subject Re: Trying to dynamically create hidden, query-only map resource 
Author c r b 
Date Nov 03, 2009 
Message A little more info on the nature of the errors: the various iterations result in one of the following:
- a null resource
- a resource with no functionalities
- the MapResourceItem throws an init failure as soon as the definition is set (w/ 'mapResourceItem.Definition = definition')
- the MapResourceManager throws an 'Object not set to an instance of an object' at either 'MapResourceManager.ResourceItems.Insert(0, mapResourceItem)' or 'MapResourceManager.CreateResource(mapResourceItem)'

Note that I've also tried the code below (a variation on the original based on the post at http://forums.esri.com/Thread.asp?c=158&f=2276&t=214628) but no joy. 
 
MapResourceItem mapResourceItem = new MapResourceItem();
GISResourceItemDefinition definition = new GISResourceItemDefinition();
mapResourceItem.Name = "QueryEnvFacs";
definition.DataSourceDefinition = "http://gis5/arcgis/services";
definition.DataSourceType = "ArcGIS Server Internet";
definition.ResourceDefinition = "Layers@onestop/IaFmFacilities";
definition.DataSourceShared = true;

mapResourceItem.Parent = MapResourceManager;
mapResourceItem.Definition = definition;
DisplaySettings displaySettings = new DisplaySettings();
displaySettings.DisplayInTableOfContents = false;
displaySettings.Visible = false;
mapResourceItem.DisplaySettings = displaySettings;
MapResourceManager.ResourceItems.Add(mapResourceItem);
//MapResourceManager.ResourceItems.Insert(0, mapResourceItem);
resource = MapResourceManager.CreateResource(mapResourceItem);
 
   
Report Inappropriate Content • Top • Print • Reply    
Subject Re: Trying to dynamically create hidden, query-only map resource 
Author Jamie Petersen 
Date Nov 03, 2009 
Message If you add the hidden map resource at design time vs dynamic, does it initialize and work as you expect - or is it only an issue when dynamic? Is there an advantage to adding it on the fly vs startup? I don't know the answer to that question, but it would seem that if you aren't drawing the layer, that it wouldn't do any harm to be loaded initially.
Regardless, below is vb code that I use to add a mapresourceitem on the fly. The bad news is that it looks similar to what you've already tried. 
 
Dim MapResourceItem = New ESRI.ArcGIS.ADF.Web.UI.WebControls.MapResourceItem()
                    Dim gisResourceItemDefinition As ESRI.ArcGIS.ADF.Web.UI.WebControls.GISResourceItemDefinition = New ESRI.ArcGIS.ADF.Web.UI.WebControls.GISResourceItemDefinition()
                    'Dim resourceName As String = "TransparentBasemap"
                    'gisResourceItemDefinition.DataSourceShared = True
                    gisResourceItemDefinition.DataSourceType = "ArcGIS Server Local"
                    gisResourceItemDefinition.DataSourceDefinition = "gisapps-2"
                    gisResourceItemDefinition.ResourceDefinition = "Layers@NewGISWEBSITE/BaseMap_Transparent"
                    MapResourceItem.Definition = gisResourceItemDefinition
                    MapResourceItem.Name = "TransparentBasemap"
                    Dim displaySettings As ESRI.ArcGIS.ADF.Web.DisplaySettings = New ESRI.ArcGIS.ADF.Web.DisplaySettings()
                    displaySettings.Transparency = 0
                    displaySettings.Visible = True
                    displaySettings.ImageDescriptor.ReturnMimeData = True
                    displaySettings.ImageDescriptor.ImageFormat = ESRI.ArcGIS.ADF.Web.ImageFormat.PNG8
                    displaySettings.ImageDescriptor.TransparentBackground = True
                    Dim htmlColor As String = "#fffefefe"
                    Dim myColor As Color = System.Drawing.ColorTranslator.FromHtml(htmlColor)
                    displaySettings.ImageDescriptor.TransparentColor = myColor
                    displaySettings.ImageDescriptor.ReturnMimeData = False
                    displaySettings.DisplayInTableOfContents = False
                    displaySettings.EnableDynamicTiling = True
                    MapResourceItem.DisplaySettings = displaySettings
                    MapResourceManager.ResourceItems.Insert(4, MapResourceItem)
                    MapResourceManager.CreateResource(MapResourceItem)
                    If MapResourceItem.FailedToInitialize Then
                        Map1.CallbackResults.Add(New CallbackResult(Nothing, "javascript", New Object() {String.Format("alert('{0}')", MapResourceItem.InitializationFailure.Message)}))
                        ScriptManager1.RegisterDataItem(Page, Map1.CallbackResults.ToString(), False)
                    End If
 
   
Report Inappropriate Content • Top • Print • Reply    
Subject Re: Trying to dynamically create hidden, query-only map resource 
Author c r b 
Date Nov 03, 2009 
Message Hey Jamie, thanks for the quick response.

Your question about why we didn't add the resource on startup into the aspx file is an excellent one (and part of the sordid details that I left out). Basically we had it on startup but it would sometimes not initialize properly or not get created at all -- and sometimes it would be fine. But it was completely unpredictable as to what state it would be in when the app started, which is why we opted to create it dynamically and have a little more control over it.

As a follow-up, we figured this out: for some reason the code I included previously didn't work when we added the new resource to an existing MapResourceManager, but if we create a new MapResourceManager and add the new resource to it, it works fine. Hopefully we've got this one licked.

Including final code snippet below (remember this is v9.3.1 so we removed some deprecated props, etc.)...

Finally, just in case anyone ever finds this post and is looking for additional info, there's some related stuff in the AGS blog here ('Creating a utility library (Part II): Creating and adding resources'):
http://blogs.esri.com/Dev/blogs/arcgisserver/archive/2008/02/22/Creating-a-utility-library-_2800_Part-II_29003A00_-Creating-and-adding-resources.aspx 
 
MapResourceManager mrm = new MapResourceManager();
            mrm.ID = "QueryMRM";

            MapResourceItem mapResourceItem = new MapResourceItem();
            GISResourceItemDefinition definition = new GISResourceItemDefinition();
            mapResourceItem.Name = "QueryEnvFacs2";
            definition.DataSourceDefinition = "http://gis5/arcgis/services";
            definition.DataSourceType = "ArcGIS Server Internet";
            definition.ResourceDefinition = "Layers@onestop/IaFmFacilities";

            mapResourceItem.Parent = mrm;
            mapResourceItem.Definition = definition;
            DisplaySettings displaySettings = new DisplaySettings();
            displaySettings.DisplayInTableOfContents = false;
            displaySettings.Visible = false;
            mapResourceItem.DisplaySettings = displaySettings;
            mrm.ResourceItems.Insert(0, mapResourceItem);
            resource = mrm.CreateResource(mapResourceItem);
            mrm.Initialize(mapResourceItem);