Jan 23, 2010

How to find the layers that intersect with an envelope or geometry + ArcGIS .Net web ADF

Layers Intersection with an Envelope:
As we know Layers intersection is a common task in GIS, here we achieve this using Identity method.
Below is the code used to find the layers in the mapresource which are being intersected 
with an envelope.

Method Call:
DataTable dt  = GetIntersectionLayers(Map1.GetFunctionalities(0),x1,y1,x2,y2);

Method Definition:
public DataTable[] GetIntersectionLayers(
ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionality gisFunctionality, double minX, 
double minY, double maxX, double maxY)
        int pixelTolerance = 1;
        DataTable[] dt = null;
        ESRI.ArcGIS.ADF.Web.DataSources.IGISResource gisResource =   gisFunctionality.Resource;
        ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality queryFunctionality =
            (typeof(ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality), null);

        string[] layerIDs = null;
        string[] layerNames = null;
        queryFunctionality.GetQueryableLayers(null, out layerIDs, out layerNames);            

        ESRI.ArcGIS.ADF.Web.Geometry.Envelope adfEnvelope =
            new ESRI.ArcGIS.ADF.Web.Geometry.Envelope(minX, minY, maxX, maxY);            

        dt = queryFunctionality.Identify(gisFunctionality.Name, adfEnvelope,
            pixelTolerance, ESRI.ArcGIS.ADF.Web.IdentifyOption.AllLayers, layerIDs);
        return dt;                

The method returns the data table with a collection of intersected layers.

Jan 2, 2010

how to zoom to a particular coordinate location in ArcGIS .Net webADF

Below is the method used to zoom in to a particular location using the coordinates. Unlike MapExtreme, ArcGIS uses ZoomFactor to zoom in and zoom out instead of ZoomWidth in MapExtreme.
private void ZoomToCoordinates()
        ESRI.ArcGIS.ADF.Web.Geometry.Point center = null;
            center = new ESRI.ArcGIS.ADF.Web.Geometry.Point(17.7244, 1.1883);
           // Numeric value is the Zoom factor(1-10 ZoomsIn & 0 to 1 ZoomsOut)
            Map1.Zoom(2, center);
        catch (Exception)
            center = null;

How to add map resource dynamically to MapResourceManager + ArcGIS 9.3 and 9.3.1 .Net WebADF

In ArcGIS webADF, After publishing the services using ArcGIS SERVER(say map service), we can just add a map resource to the MapResourceManager manually in design time.

Now lets see how to add the map resource dynamically through code. Because mostly we may have multiple map resource that has to be shown only on request.

Below is the code through which we can achieve this.

Method call:
AddMapResourceDynamically("GlobalService", "Layers@GlobalService", false);
- GlobalService is the service name.
- Layers@GlobalService is the service definition(i.e Layers@Service_Name is the format)
- true or false to list the resource in the TOC Control.

Method Definition:
private void AddMapResourceDynamically(string resName, string resDefinition, bool IsTOC)
        string m_ResourceName = string.Empty;
        MapResourceItem mapResourceItem = null;
        GISResourceItemDefinition resDef = null;
        DisplaySettings displaySettings = null;
            mapResourceItem = new MapResourceItem();
            resDef = new GISResourceItemDefinition();
            mapResourceItem.Name = resName;

            // The services url which we use to fetch the services.
            resDef.DataSourceDefinition = @"http://hostname/arcgis/services";
            resDef.DataSourceType = "ArcGIS Server Internet";
            resDef.ResourceDefinition = resDefinition;
            resDef.DataSourceShared = true;
            mapResourceItem.Parent = MapResourceManager1;
            mapResourceItem.Definition = resDef;

            displaySettings = new DisplaySettings();
            displaySettings.Transparency = 0;
            displaySettings.Visible = true;
            displaySettings.DisplayInTableOfContents = IsTOC;
            displaySettings.ImageDescriptor.TransparentColor = System.Drawing.Color.White;
            displaySettings.ImageDescriptor.TransparentBackground = true;
            mapResourceItem.DisplaySettings = displaySettings;

            // Insert the new resource item at the beginning (top).             MapResourceManager1.ResourceItems.Insert(MapResourceManager1.ResourceItems.Count, mapResourceItem);

            // Create the map resource and return a reference in case it will be the 
            // primary map resource.
            IMapResource mapResource =       MapResourceManager1.CreateResource(mapResourceItem);

            // If no other resource items are present, set the new map resource item as the 
            // primary map resource.
            if (MapResourceManager1.ResourceItems.Count < 1)
                Map1.PrimaryMapResource = mapResourceItem.Name;
        catch (Exception)
            mapResourceItem = null;
            resDef = null;
            displaySettings = null;

The above code will add the map resource dynamically to the MapResourceManager and display it on the map on runtime.