I am not sure what I am missing in this code. I am querying a point service and get a result. and then trying to convert the result to graphic to add it on the map... but no luck.
var querystreetIntersect = new Query(); querystreetIntersect.where = where; querystreetIntersect.returnGeometry = true; streetLayer.selectFeatures(querystreetIntersect, FeatureLayer.SELECTION_NEW, function (features) { var lat = features[0].attributes["Lat"]; var lon = features[0].attributes["Long"]; //var point = new Point(lon, lat, new SpatialReference({ wkid: 102100 })); var simpleMarkerSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_SQUARE, 12, new SimpleLineSymbol().setStyle(SimpleLineSymbol.STYLE_SOLID).setColor(new Color([100, 100, 100])), new Color([0, 0, 0, 0])); var graphic = features[0]; graphic.setSymbol(symbol); console.log(features[0]); map.graphics.add(graphic); map.centerAndZoom([lon, lat], 19); });
here is the result object from the console:
Solved! Go to Solution.
Sorry guys, the problem was my service layer projection system. I had to re-project it in ArcMap in the correct projection and then republished the service.
Now it works just fine.
Thank you all...
Richard,
It is a bit hard to say without having more code for context. A couple of things I noticed. You are setting the graphic symbol with the symbol variable instead of the simpleMarkerSymbol that you just created. Is that correct?
Is the spatial reference appropriate for the graphic? This may also cause the graphic to not be displayed.
Regards,
Tom
Thank you Tom for replying. Correct, I changed the "symbol" with "simpleMarkerSymbol" but still nothing. the graphic is not added to the map.
Richard,
Did you look at the spatial reference? That may be the culprit?
Regards,
Tom Sellsted
Supervising Senior Analyst
Tom.Sellsted@YakimaWA.gov<mailto:Tom.Sellsted@YakimaWA.gov>
129 North 2nd Street, Yakima, WA 98901<x-apple-data-detectors://2/1>
Phone (509) 576-6602<tel:(509)%20576-6602> | FAX (509) 249-6835<tel:(509)%20249-6835>
46° 36' 17.86"N 120° 30' 18.23"W
the spatial reference may be the issue here but I am not quite sure to verify that. I tried graphic.outSpatialReference = { wkid: 102100 };
still nothing. is there another way to convert the spatial reference?
Richard,
I think somehwere in there you need to create an actual graphic, so you can add it to the graphics layer?
Graphic | API Reference | ArcGIS API for JavaScript
You got your symbol and the geometry, all you need to do is create a graphic from it.
Tim
Sorry guys, the problem was my service layer projection system. I had to re-project it in ArcMap in the correct projection and then republished the service.
Now it works just fine.
Thank you all...
Richard,
Glad you got it working!
Regards,
Tom