Well, here is Part I of using the Polygon Tool in the Web ADF that I promised a while ago. As you can see from the screen shot below, this tool will let the user create a polygon area and retrieve some stats about the area they defined. Let me state right away that I don’t work for ESRI and by using this code you do so at your own risk.
Anyway, let’s get to it shall we?
In my mock up AGS App shown in the screenshot I’m using all ESRI base data. The points layer is a Zip Codes feature class with some random attributes such as population, population per SQMI, SQMI, etc. I used this layer because it was the first one I saw that I could use for computing some averages. You can use any layer (obviously..), just make the necessary changes.
I have two (2) services in my MapResourceManager: 1. “Graphics” (in Memory Layer) 2. “BaseMap” (pooled service created from ESRI Base Data) . We’ll use the graphics layer to return a graphic of what the user defined as their polygon area. You can go through the attached code (clsCreateGraphicPoly) and change the color, transparency, etc. of the graphic that is returned.
As for the code, here are the bullet points:
- First we add the custom Polygon tool to the toolbar in the code view of the Default.aspx page
- If you are using the Web Mapping Template in VS 2005 you can use the “measure-polygon.png” already included in the Images folder.
- You may also need to resize the toolbar for our new tool to show up properly
- Here is the HTML for the Polygon tool:
<esri:Tool DefaultImage=”images/measure-poly.png” JavaScriptFile=”" HoverImage=”images/measure-poly.png” ClientAction=”Polygon” ToolTip=”Polygon” SelectedImage=”images/measure-poly.png” Name=”Polygon” Text=”Polygon”></esri:Tool>
- Note that ClientAction=”Polygon”
- Now we can start adding code when the Map1_Polygon event is fired in the Default.aspx.vb/cs
- I think I’ve commented the code fairly well so I’m not going to go through it line by line
- What we basically do is first create the graphic (as an ElementGraphicsLayer) and add it to the Graphics resource
- Then we send the map points (from the user created polygon) into a function that uses a SpatialFilter to query out records and perform calculations on them
- Once the calculations are returned from the function, we then automatically expand the Results Panel and use some of the Web ADF javascript functions to change the innerHTML of the panel to our averages
Pretty cool huh? Maybe? A little? Well I think so.
Code is below. Sorry about the word .docs…I think it’s the only way I can attach it. Still new to wordpress…
Oh and why Wisconsin in the screenshot?? Because Wisconsin is awesome.
Leave some comments!!
-Adam
very interesting. i’m adding in RSS Reader