Select to view content in your preferred language

Add graphic point after query

4169
7
Jump to solution
05-21-2015 03:09 PM
RichardMoussopo
Frequent Contributor

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:

graphicPoint.PNG

0 Kudos
1 Solution

Accepted Solutions
RichardMoussopo
Frequent Contributor

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...

View solution in original post

0 Kudos
7 Replies
TomSellsted
MVP Alum

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

RichardMoussopo
Frequent Contributor

Thank you Tom for replying. Correct, I changed the "symbol" with "simpleMarkerSymbol" but still nothing. the graphic is not added to the map.

0 Kudos
TomSellsted
MVP Alum

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

0 Kudos
RichardMoussopo
Frequent Contributor

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?

0 Kudos
TimWitt2
MVP Alum

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

0 Kudos
RichardMoussopo
Frequent Contributor

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...

0 Kudos
TomSellsted
MVP Alum

Richard,

Glad you got it working! 

Regards,

Tom

0 Kudos