Editor - OnDrawComplete

4250
8
01-31-2015 04:40 PM
RichardMoussopo
Occasional Contributor III

I have this logic that I am trying to accomplish: I would like to get the centroid point of the polygon after being created and then perform the reverse geocode from that point to get informtions such as the full address, the county and township.

Any advice on accomplishing this?

Also, since the update on editor is done automatically, I am wondering if there could be an event handler for editor complete or update complete!?

0 Kudos
8 Replies
TeroRönkkö
Occasional Contributor

There is:

public event OnCreateFeatureEventHandler OnCreateFeature

There is help page (didn't find current doc, but the syntax is the same)

ArcObjects 10 .NET SDK Help

Listen to that event, get the feature, calculate center, do reversegeocodemagic, profit!

0 Kudos
OwenEarley
Occasional Contributor III

The OnCreateFeatureEventHandler is only for ArcObjects - this question relates to the JavaScript API

Rene has the right approach hooking in to the draw-end event of the Draw toolbar.

Also, since the update on editor is done automatically, I am wondering if there could be an event handler for editor complete or update complete!?

Are you referring to when the locator has returned a result or something else here?

Rene's example logs the address result to the console window but you could also store it.

TeroRönkkö
Occasional Contributor

Oh, sorry for confusing. I have lot to learn from this Geonet - I didn't notice the TOPIC of the discussion at all

0 Kudos
ReneRubalcava
Frequent Contributor

You can grab the centroid of the polygon geometry and use that with the Locator task to find the address.

You'll want to use the locationToAddress method.

It would look something like this

//somewhere add listener
tb = new Draw(map);
tb.on("draw-end", addGraphic);

// listener method
function addGraphic(evt) {
  var pt = evt.geometry.getCentroid();
  locator.locationToAddress(pt, 100).then(function(addresses) {
    console.debug('Address Results', addresses);
  });
  map.graphics.add(new Graphic(evt.geometry, symbol));
}

I tried making a JSBIN to demonstrate, but you need to add a proxy to use the Locator Task service, so it won't work in entirely, but should give you a good start.

Hope that helps

0 Kudos
RichardMoussopo
Occasional Contributor III

Thank you Dene.

I am trying your approach which I think should be able to work.

the getCentroid method works fine but when calling the reverse geocode I get this error: Invalid query parameters which I believe may be related to the coordinates x and y?

getCentroid.PNG

0 Kudos
ReneRubalcava
Frequent Contributor

You're going to want to use webMercatorUtils to convert the pt to match the GeocodeServer. That should work in most cases.

RichardMoussopo
Occasional Contributor III

Hi Rene,

Sorry I am still having problems with this.

here is the code

  map.graphics.add(new Graphic(evt.geometry, symbol));

        var point = evt.geometry.getCentroid();

        var point2 = new esri.geometry.Point(Number(point.x), Number(point.y), map.spatialReference);

        var mp = esri.geometry.geographicToWebMercator(point2);

     

        console.log(point2.x + " , " + point2.y);

        console.log(mp);

and here is the output : and it is still failing when calling locator.locationToAddress()

getCentroidReversegeocode.PNG

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Richard,

  What is the Spatial Reference of the evt that you are getting back? In your code you are creating an new point and setting the new points SR to the maps and then using ToWebMercator. So if the map is already 102100 then this process is not right. What SR is your GeoCodeServer using?

If you GeocodeServer allows Geographic coords (i.e 4326) the you can use this line:

locator.locationToAddress(webMercatorUtils.webMercatorToGeographic(evt.mapPoint), 10);