19 December, 2007

Getting the map to zoom to a feature in ESRI webADF is a chore

ESRI can be as frustrating as it can get. My lack of experience with ASP.NET 2.0/3.0 combined with the vast differences betwen the desktop functionality of ArcGIS and the web functionality of ArcIMS / WebADF is giving me gray hair faster then my kids every could dream of doing.

I have a .NET pretty much out of the box site - that is, I went into "ArcIMS Web Manager for the Microsoft .NET Framework" and setup a new site. I have some queries that had to be customized, and I ran out of time trying to get the TaskResults panel to display the query results (I'll post about that experience when I have a little more time), so I put them in an HTML table in their own panel. I have a hyperlink in the table which, when clicked, should zoom to that feature on the map. I have looked and, and am using some code from this thread how can i zoom to my selected features - only it isn't working fully.

// This is the method to zoom to the feature, param 'key' is the objectid of the feature, and the param 'layer' is the name of the feature layer
protected void ZoomToFeature(string key, string layer)
{
ESRI.ArcGIS.ADF.Web.DataSources.IMS.MapFunctionality mf;
ESRI.ArcGIS.ADF.IMS.Carto.MapView mv;
mf = (ESRI.ArcGIS.ADF.Web.DataSources.IMS.MapFunctionality)Map1.GetFunctionality(0);
mv = mf.MapView;
ESRI.ArcGIS.ADF.IMS.Carto.Layer.FeatureLayer queryLayer;
queryLayer = (FeatureLayer)mv.Layers.FindByName(layer);
Filter queryFilter = new Filter();
QueryParameters queryParams = new QueryParameters(queryFilter);
queryFilter.WhereExpression = "ObjectID = '" + key + "'";
queryFilter.Tolerance = 20;
queryFilter.ToleranceUnits = BufferUnits.Meters;
queryParams.ReturnGeometries = true;
queryParams.ReturnGlobalEnvelope = true;
ESRI.ArcGIS.ADF.IMS.Display.Symbol.FeatureSymbol fs = new ESRI.ArcGIS.ADF.IMS.Display.Symbol.SimpleFillSymbol(System.Drawing.Color.White, System.Drawing.Color.Red, ESRI.ArcGIS.ADF.IMS.Display.Symbol.PolygonFillType.Solid);
ESRI.ArcGIS.ADF.IMS.Display.Renderer.SimpleRenderer sr = new ESRI.ArcGIS.ADF.IMS.Display.Renderer.SimpleRenderer(fs);
queryLayer.Visible = true;
FeatureTable ft = queryLayer.Query(queryParams);
if (ft.Rows.Count > 0)
{
ESRI.ArcGIS.ADF.IMS.Geometry.Geometry featureGeom = (ESRI.ArcGIS.ADF.IMS.Geometry.Geometry)ft.Rows[0]["#SHAPE#"];
ESRI.ArcGIS.ADF.Web.Geometry.Geometry adfGEom = ESRI.ArcGIS.ADF.Web.DataSources.IMS.Converter.ToADFGeometry(featureGeom);
ESRI.ArcGIS.ADF.Web.Geometry.Envelope adfEnv = ESRI.ArcGIS.ADF.Web.Geometry.Envelope.GetMinimumEnclosingEnvelope(adfGEom);
Map1.Extent = adfEnv;
}
Map1.Refresh();
}

// This is the code in RaiseCallbackEvent(string responseString) method which calls the ZoomToFeature method
this.ZoomToFeature(eventArg, layerArg);
response = Map1.CallbackResults.ToString();

I am getting new envelope for the feature, and I am setting the map extents to that envelope. I know this works because I put some dummy code in a Map1_ExtentsChanged event handler and checked to ensure the map extents were changed. Then I hit Map1.Refresh(); but the map does not change. I'm returning the Map1.CallBackResults.ToString();, but I'm ignorant of what to do with the results on the client side. The RaiseCallbackEvent method returns the 'response' string.


After playing around and doing some more searching with different keywords, I found this thread; The ESRI Map control does not refresh ..... which talks about client side map.redraw(); giving the following example:

var map = Maps['<%=Map1.ClientID %>'];
map.redraw();

I thought this would solve my problem and it almost-but-not-quite does. It does redraw the map (at least it looks like it does). But what I get is a completely blank map until I either zoom in or out. Then the map appears zoomed to roughly the correct location (depending on if I zoomed in or out to make it show up). Also works using the mouse wheel.




Technorati Tags: , , , ,

13 December, 2007

I might be going crazy

This is getting more annoying by the fracking minute!!!!!!!!

I need a search with cascading combo boxes. That is, when the search panel is displayed, combobox1 is populated, and combobox2 is empty. When the user selects a value from combobox1, it then populates combobox2 with values based on combobox1. Simple enough right? I get that population of the boxes down pat, no problems there. Doing through Callback and everything so the page doesn't have to refresh or anything like that.

Here is my problem. I need the results to display in the ESRI.ArcGIS.ADF.Web.UI.WebControls.TaskResults results panel - we'll call it TaskResults1 (because that is what it is called when the site is created through the ESRI ArcIMS manager). I have tried just putting the code in there, but to no avail. I have tried creating a QueryAttributesTask and defaulting the values to what I need, and executing the task. Still no dice.

The values get put into the TaskResults1 results, but they just don't display. I can't figure why they don't display. I know they are there because after I perform the query, if I do a canned search, or use the MapIdentify feature (both of which add data to the TaskResults1 container), the results display with the new data.

I have tried finding help on the ESRI forums, but that is slow and I'm on a deadline.

I'll keep trying different wild and crazy stuff to see if I can figure it out.

Hmmmm....I wonder if I can refresh the TaskResults1 container from client side java?