I'm currently updating the Geocoder in WAB to work like the link below but I can't figure out how to add a marker when an address is found. Can someone tell me why this code is not adding a graphic after inputting an address in the geocoder?
Trigger Layer(s) Popup with Feature.Geometry
onFindResults: function(results) {
//Check to see if the user typed an MGRS or USNG string
this.lastMgrsResult = this.lookupMgrs(results.results.value);
if (null !== this.lastMgrsResult) {
// Get reference ellipsoid coordinates of the current coordinate system
// var mapWkid = this.map.spatialReference.wkid;
// var srWkid = csUtils.isProjectedCS(mapWkid) ?
//csUtils.getGeoCSByProj(mapWkid) : mapWkid;
//Make a new object just like the objects in results.results.results
var point = new Point(
this.lastMgrsResult.longitude,
this.lastMgrsResult.latitude,
new SpatialReference({
wkid: 4326 //srWkid should use the ellipsoid SR of the current coordinate system
}));
var extent = this.map.extent.centerAt(point);
var symbol = new SimpleMarkerSymbol();
symbol.setStyle(SimpleMarkerSymbol.STYLE_SQUARE);
symbol.setColor(new Color([153,0,51,0.75]));
var graphic = new esri.Graphic(point, symbol);
map.graphics.add(graphic);
var resultObject = {
extent: extent,
feature: feature,
name: this.lastMgrsResult.text
};
//Insert at start of results list
results.results.results.unshift(resultObject);
}
},
Solved! Go to Solution.
Giovanni,
Giovanni,
Thank you for taking the time to answer this question. I had the three problems you mentioned, I was missing the "esri/Color" in the define section and I needed the "this.map." to map.graphics.add(graphic), and I had it in the wrong section of the script. Here's the working code.
if (feature) { |
var mpPt = feature.geometry;
this.map.centerAndZoom( mpPt, 20); | |||
var symbol = new SimpleMarkerSymbol(); | |||
symbol.setStyle(SimpleMarkerSymbol.STYLE_SQUARE); | |||
symbol.setColor(new Color([255,0,0])); |
var graphic = new esri.Graphic(mpPt, symbol);
this.map.graphics.add(graphic); |
setTimeout(lang.hitch(this, function(){ var scrPt = this.map.toScreen(mpPt); this.map.emit("click", { bubbles: true, cancelable: true, screenPoint: scrPt, mapPoint: mpPt }); }), 1000);
} else if (extent) {
this.map.setExtent(extent);
}
Thanks again!