Select to view content in your preferred language

Please help: "On click" or "onDraw" handler issues

805
5
08-14-2012 12:30 PM
DorotheaKnigge
Deactivated User
Hello from a frustrated beginner,

I have a "find" datagrid which is working well.  I also have an "identify" grid with muliple tabs for identifying such things as school districts, precincts, and etc which functions by first clicking a "select" button.  The Identify portion works well by itself. It also works the the first time it is used with the selected record of the "find" datagrid  but thereafter it causes problems.

It would be awesome if the two could be used interchangeably. Could someone help me sort out my code and the "On click" or "On draw' handler?
Or perhaps there is a better way?

Thank you for any help or suggestions,

Dorothea
0 Kudos
5 Replies
StephenLead
Honored Contributor
Welcome to the JS API!

Can you provide further information on exactly what is going wrong? Are you able to link to your site?

There are a few potential problems in your code. Minor errors include:

var dynamicMapServiceLayer = new esri.layers.ArcGISDynamicMapServiceLayer("http://xxxxxxxxx/ArcGIS/rest/services/Hillshade/MapServer"); 
map.addLayer(dynamicMapServiceLayer); 
  
var dynamicMapServiceLayer = new esri.layers.ArcGISDynamicMapServiceLayer("http://xxxxxxxxx/ArcGIS/rest/services/WaterBodies_WebMercatorAux/MapServer",{"opacity":0.9}); 
map.addLayer(dynamicMapServiceLayer);


Without a unique name, you won't be able to do anything further with these layers. It would be better to name them uniquely.

dojo.connect(map, 'onLoad', function(theMap) {
  //resize the map when the browser resizes
  dojo.connect(dijit.byId('map'), 'resize', map,map.resize);
});

dojo.connect(map,"onLoad",mapReady);


These should be conflated into a single function.

However, I think your main problem is here:

function onDrawEnd(extent){
   toolBar.deactivate();
   executeIdentifyTask(extent);


executeIdentifyTask is expecting a point location, and you've given it a rectangular extent. When you use the line:

clickHandler = dojo.connect(map, "onClick", executeIdentifyTask);


the onClick handler passes the point clicked by the user. This is what the identifyTask is expecting:

function executeIdentifyTask(geom) {
   identifyParams.geometry = geom;


Hope this helps,
Steve
0 Kudos
DorotheaKnigge
Deactivated User
Good Morning Steve,

I much appreciate your response.

1. Thank you for the tip on giving all dynamiclayers unique names.

2. I'm not quite clear on the second part about conflating the following into a single function.
         dojo.connect(map, 'onLoad', function(theMap) {
         //resize the map when the browser resizes
        dojo.connect(dijit.byId('map'), 'resize', map,map.resize);
         });       
         dojo.connect(map,"onLoad",mapReady);

    If you meant removing the :
       
              //resize the map when the browser resizes
              dojo.connect(dijit.byId('map'), 'resize', map,map.resize);

    from the mapReady function, I have done that without any apparent consequences to the application.


3.  Now for the real problem (s).
    Let me try and better explain what I'm finding.  If I use the Identify "SELECT" button to draw a selecting box within a map
    parcel the attributes are added to the top region grid.  I am able to use the scroll wheel to zoom in and out.
    If I then use the find "SEARCH" box to find an address or parcel, all relevant addresses/parcels are listed in the grid at the 
    bottom region. Clicking on a grid row will zoom to that location. I can zoom in and out using the scroll wheel or the slider. I can
    also select another grid row and zoom to that record.  However, if I use the identify "SELECT" button after zooming to a grid
    row I can no longer zoom to another grid row and the "zoom in and out" functions suffer.

    I know I have a problem with the

            //identify portion
            function onDrawEnd(extent){
            toolBar.deactivate();
            executeIdentifyTask(extent);
            }

    and the onClick handler.  I have tried changing the onDrawEnd references to onClick  but it didn't work.  Perhaps I need to do
    away with the "SELECT" function  altogether?  What would be the best way?

Thanking you for your help and advice,

Dorothea
0 Kudos
StephenLead
Honored Contributor
Hi Dorothea,

It's really hard (for me, at least!) to debug this properly without being able to run it. Is there any chance you can put this on a public site so we can test it?

However, if I use the identify "SELECT" button after zooming to a grid row I can no longer zoom to another grid row and the "zoom in and out" functions suffer.


It sounds like there's a problem with the event listeners, which are getting out of sync or otherwise failing. This would (probably) be easier to debug by stepping through it.

If you haven't already done so, try installing Firefox and Firebug, which will allow you to step through your code to ascertain where the problem lies.

Try putting a breakpoint inside the routine you suspect is causing the problem, and step through it to see which line throws the error.

I know I have a problem with the

//identify portion
function onDrawEnd(extent){
  toolBar.deactivate();
  executeIdentifyTask(extent);
}


and the onClick handler. I have tried changing the onDrawEnd references to onClick but it didn't work. Perhaps I need to do
away with the "SELECT" function altogether? What would be the best way?


If you step into executeIdentifyTask in this case, you'll probably see that extent is a rectangle, whereas this function is expecting a point. You'll need to adjust your logic so that you're generating a point with which to identify.

Not being able to run your code, I don't understand why you're running the identify after the drawing ends, but hopefully since you understand what you're trying to do, this will make sense.

Good luck,
Steve
0 Kudos
DorotheaKnigge
Deactivated User
Hi Steve,

Thank you for taking a look at this. At this point I don't think I can put it in a public place but I will check again with IT.

I will try debugging with Firebug and let you know what I discover. 

Please let me know if you come up with other possible ideas on how to solve the problem.

Dorothea
0 Kudos
DorotheaKnigge
Deactivated User
Hi Steve,

I have since changed my project from using an identify grid to using an Identify info window with tabs. 

I did, however, discover that on starting the identify function I was clearing the graphics of my find function which of course kept me from selecting another grid row and zooming to it.  I can't believe I didn't catch that earlier.

Thank you again:)

Dorothea
0 Kudos