URL Parameters Sample (Polygons vs. Points)

1188
5
Jump to solution
06-05-2012 05:15 AM
KentuckyDGI
New Contributor II
We've been working with this sample http://help.arcgis.com/en/webapi/javascript/arcgis/help/jssamples_start.htm and are having some issues using it with Point data rather than the Polygon data that is leveraged in the sample. When we change the code to use a point based data source we are able to get it to place a PictureMarkerSymbol at the selected point's location, however the popup window does not appear and it does not re-center the map as it does with the Resource Center Sample.

Below are links to our two versions:

http://kygeonet.ky.gov/kia/edis/simplemap2.htm?entityid=28
http://kygeonet.ky.gov/kia/edis/simplemap3.htm?entityid=28

I suspect my issue is somewhere within this function but I may be totally off base:

//when users click on the map select the parcel using the map point and update the url parameter         dojo.connect(map, 'onClick', function (e) {           var query = new esri.tasks.Query();           query.geometry = e.mapPoint;           var deferred = sites.selectFeatures(query, esri.layers.FeatureLayer.SELECTION_NEW, function (selection) {             //update the url param if a parcel was located             if (selection.length > 0) {               var entityid = selection[0].attributes['OBJECTID'];               //Refresh the URL with the currently selected parcel               if (typeof history.pushState !== 'undefined') {                 window.history.pushState(null, null, "?entityid=" + selection[0].attributes.OBJECTID);               }             }           });           map.infoWindow.setFeatures([deferred]);           map.infoWindow.show(e.mapPoint);          });


Please let us know if you've run into this previously or have any ideas on how to resolve the issue.

Thanks so much!
0 Kudos
1 Solution

Accepted Solutions
JenniferGaa
New Contributor III
I recently had to do a similar type of selection on a point layer using the user click.  In my layer points could be on top of each other, and the client wanted to ensure that all points were selected, not just the one drawn on top.  So I actually changed the point to an extent (buffered the click point by 3 pixels), and used that to do the selection.  Below are code snippets of what I used:

var query = new esri.tasks.Query();
query.geometry = pointToExtent(map, evt.mapPoint, 3); //buffers click point by number of pixels(3)

...

function pointToExtent(map, point, toleranceInPixel) {
    var pixelWidth = map.extent.getWidth() / map.width;
    var toleraceInMapCoords = toleranceInPixel * pixelWidth;
    return new esri.geometry.Extent(point.x - toleraceInMapCoords,
                     point.y - toleraceInMapCoords,
                     point.x + toleraceInMapCoords,
                     point.y + toleraceInMapCoords,
                     map.spatialReference);
}


I played with a copy of your code a bit on JSFiddle here: http://jsfiddle.net/xV8bh/ and got it working.  Note that I have some alerts included that you will want to remove or comment out.

View solution in original post

0 Kudos
5 Replies
JenniferGaa
New Contributor III
Which sample are you using?  Your link points to the main samples page.
0 Kudos
KentuckyDGI
New Contributor II
So sorry for the confusion.

I'm using the HTML5 > Url Parameters and Browser History

http://help.arcgis.com/en/webapi/javascript/arcgis/help/jssamples_start.htm#jssamples/exp_history.ht...
0 Kudos
JenniferGaa
New Contributor III
I recently had to do a similar type of selection on a point layer using the user click.  In my layer points could be on top of each other, and the client wanted to ensure that all points were selected, not just the one drawn on top.  So I actually changed the point to an extent (buffered the click point by 3 pixels), and used that to do the selection.  Below are code snippets of what I used:

var query = new esri.tasks.Query();
query.geometry = pointToExtent(map, evt.mapPoint, 3); //buffers click point by number of pixels(3)

...

function pointToExtent(map, point, toleranceInPixel) {
    var pixelWidth = map.extent.getWidth() / map.width;
    var toleraceInMapCoords = toleranceInPixel * pixelWidth;
    return new esri.geometry.Extent(point.x - toleraceInMapCoords,
                     point.y - toleraceInMapCoords,
                     point.x + toleraceInMapCoords,
                     point.y + toleraceInMapCoords,
                     map.spatialReference);
}


I played with a copy of your code a bit on JSFiddle here: http://jsfiddle.net/xV8bh/ and got it working.  Note that I have some alerts included that you will want to remove or comment out.
0 Kudos
KentuckyDGI
New Contributor II
Thanks so much!
I'll look into this in just a bit.
It makes sense that you'd have to convert the point information to an extent in order for the zoom to work.
That function obviously does the trick!
0 Kudos
akpagaakpaga
New Contributor
Thank JGaa..Your solution has worked for mine...Thanks A lot..
0 Kudos