AnsweredAssumed Answered

Need to snap entry in GeoForm to another layer in webmap.

Question asked by cmathers on Aug 4, 2016

I'm trying to use a GeoForm and the wHydrantInspection feature class from LGIM for my county fire fighters to inspect hydrants. I have spoken to them several times about the virtues of zooming in and not having their inspection point be 60 feet away from the hydrant they are inspecting but its not getting through. In the app if you click or tap on a feature in the layer being edited, wHydrantInspection in this case, you identify on it and get a popup. I have wHydrant also in the webmap as a map service and want to have it so that when a user clicks in the normal click tolerance to get the popup for that hydrant it will take the geometry from that point and use it for the GeoForm graphic/submission. The actual popup for the hydrant is unnecessary. I assume I need to add code to the on click event of the map in GeoForm\js\main.js (line 1584) but I don't know much JavaScript so I don't know how to go about it. I would love to grab other attributes off the hydrant point and pre-populate the form a bit but that's icing for a cake I haven't baked yet. Below is the on click event from the latest GeoForm version available on ESRI's GitHub.

 

// map click
        on(this.map, 'click', lang.hitch(this, function (evt) {
          //remove the location-error message as soon as the point on the map is selected.
          this._removeErrorNode(dom.byId("select_location").nextSibling);
          this._clearSubmissionGraphic();
          this.addressGeometry = evt.mapPoint;
          this._setSymbol(this.addressGeometry, true);
          // get coords string
          var coords = this._calculateLatLong(evt.mapPoint);
          domAttr.set(dom.byId("coordinatesValue"), "innerHTML", coords);
          this._setCoordInputs(evt.mapPoint);
        }));

 

UPDATE: Poking at it a bit more I played with the app with Fiddler open and it is registering a query against the whydrant layer when I click anywhere on the map. I just need to grab that response JSON and get the geometry. Its going somewhere in the app but  I don't know where.

 

UPDATE 2: Got it to work by swapping the hydrants from a map service to a feature service. It changes the way the webmap renders the objects into the map I guess because when you click on a feature service the event object gets the graphic property which has a geometry property. I check for this and grab that geometry instead of using the event.mapPoint geometry which is where I actually click. The tweaks to the on click section are below. Not shown is that "snapGeometry: null" was added to the declarations at the top. This tweak doesnt take into account the geometry that results from dragging the marker somewhere else after you click. I might disable dragging entirely.

 

// map click
        on(this.map, 'click', lang.hitch(this, function (evt) {
          //remove the location-error message as soon as the point on the map is selected.
          this._removeErrorNode(dom.byId("select_location").nextSibling);
          this._clearSubmissionGraphic();
          console.log(evt);
          'graphic' in evt && evt.graphic._graphicsLayer.id === "CountyHydrants_5346" ? console.log('graphic') : console.log('event');
          //this.addressGeometry = evt.mapPoint;
          this.snapGeometry = 'graphic' in evt && evt.graphic._graphicsLayer.id === "CountyHydrants_5346" ? evt.graphic.geometry : evt.mapPoint;
          this.addressGeometry = this.snapGeometry;
          this._setSymbol(this.addressGeometry, true);
          // get coords string
          //var coords = this._calculateLatLong(evt.mapPoint);
          var coords = this._calculateLatLong(this.snapGeometry);
          domAttr.set(dom.byId("coordinatesValue"), "innerHTML", coords);
          this._setCoordInputs(evt.mapPoint);
        }));

Outcomes