Select to view content in your preferred language

Map.graphics.add() not showing points on the map

8455
16
Jump to solution
11-13-2013 10:25 AM
IrfanClemson
Occasional Contributor II
Hi,
I have inherited an ArcGIS JavaScript API project. I am very new to this API in particular and ArcGIS in general. Currently, one part of the code is very problematic--populating the map with some query task's results. Here is a code snippet. In the debugger I can see the returned results, including geometry of individual result rows. But they never show up on the map.

  function showResults(results) {//This bounds the results into the data grid from doFind() function      var symbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([98,194,204]), 200), new dojo.Color([98,194,204,0.5]));       for(var i=0; i < results.features.length; i++){        //map.graphics.add(results.features);     var graphic = results.features;     graphic.setSymbol(symbol);     map.graphics.add(graphic);      }              }    


What could be happening? I don't think posting thousands of line of code will help. But the debugger does show information for each row, such as:
map.graphics.graphics.geometry[0]->
- _shape=null
- type=point
- x= 283265
- y= 3955658
- symbol [object data]

and when I go to:
http://myserver/arcgis/rest/services/NPS_Location_Search/MapServer/0
then, under Drawing Info, I can see the colored dot object for Symbol.

I can give more info about how the various maps are laid out if that helps?

Thanks!
Meengla
0 Kudos
1 Solution

Accepted Solutions
ReneRubalcava
Frequent Contributor II
You mway want to make sure the results are in the proper spatial reference.
Make sure you have this in your code some where before executing the QueryTask.
query.outSpatialReference = map.spatialReference;

https://developers.arcgis.com/en/javascript/jsapi/query-amd.html#outspatialreference

This has bitten me on more than one occasion.

View solution in original post

0 Kudos
16 Replies
ReneRubalcava
Frequent Contributor II
You mway want to make sure the results are in the proper spatial reference.
Make sure you have this in your code some where before executing the QueryTask.
query.outSpatialReference = map.spatialReference;

https://developers.arcgis.com/en/javascript/jsapi/query-amd.html#outspatialreference

This has bitten me on more than one occasion.
0 Kudos
IrfanClemson
Occasional Contributor II
@Odoe,
I just put the line query.outSpatialReference = map.spatialReference;
before query.execute function and now get an error like '_3db undefined'; this error's stack seems to be from:

require({cache:{"esri/layers/TimeReference":function(){define(["dojo/_ ...

I did put a dojo.require("esri.SpatialReference"); toward the top of the javascript file--where other 'require' are but still the same error.

I will research the cause of this latest problem... If someone knows then please save me some time--it's been enough struggle with this already.

Thanks!
0 Kudos
KaitlynnDavis
Occasional Contributor
Your graphics might actually be getting added. I would recommend commenting out the map.spatialReference line that is giving you the error statement just for now and run your code, then try to zoom as far away as possible. Your point graphics might be appearing in a whole other part of the globe, in which case you then know for sure that you have a projection issue
0 Kudos
IrfanClemson
Occasional Contributor II
@Kait,
Okay, I commented out the
query.outSpatialReference =  map.spatialReference;//
line and then did the query and then zoomed out--and once I tried to zoom out of the extents of the US continental (the lower 48) I saw the same error as above: '_3eb undefined';
so even though the query.outSpatialReference is commented out I am getting the same error.
I tend to agree with you and @Odoe that this is some extent issue?
Thanks!
0 Kudos
vinayb
by
New Contributor III
I am getting exactly the same problem , map.graphics.add() is not showing the gaphics.
I had to change my code to from queryTask.execute() to esri.requst i am faicng this issue ever since.

my query had below condition:
var qTask= new QueryTask(queryTaskUrl);
            var query = new Query();
            query.returnGeometry = true;
            query.maxAllowableOffset = 4326;
            query.where = executableQuery;
            query.spatialRelationship = Query.SPATIAL_REL_CONTAINS;
            var spRef = new esri.SpatialReference({
                wkid: 102100
            });
            query.outSpatialReference = spRef



hence i changed my code to


       
var spRef = new esri.SpatialReference({
                wkid: 102100
            });
   var queryRequest = esriRequest({
      url : queryTaskUrl,
      content : {
       f : "json",
     returnGeometry: true,
     where : executableQuery,
     outSR:spRef ,
     maxAllowableOffset:4326,
     spatialRel:"esriSpatialRelContains"
      },
      callbackParamName : "callback"
     }, {usePost : true});
   handleAs : "json",
    queryRequest.then(showResults, function (error) {
     console.log("Error: ", error.message);
    });


var color="#919191";
        try {
            var symbol = new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID, new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new Color("#AED8EC"), 1), new Color(color));
            dojo.forEach(featureSet.features, function(feature){
                console.log(" iterating each feaures " +feature);
    //var graphic = new FeatureSet(feature);
    var graphic=new FeatureSet(feature);
    //var graph = new Graphic(graphic);
    graphic.setSymbol(symbol );
    console.log(" graphic feaures " +graphic.symbol.color);
    console.log(" graphic visible " +graphic.visible);
             map.graphics.add(graphic); 
            });
        } 
        catch (e) {
            console.log(" issue in iterator " + e);
        }



now map.graphics.add() does not show up

but when i change
belwo line
outSR:map.spatialReference


graphics shows but it not exactly as expected hence how do i know what is exact valuel
0 Kudos
IrfanClemson
Occasional Contributor II
@VinayBa,
I tried to changed to your code but in the showResults function I am only getting field names in the results--not actual data. If I could get featuresets then maybe the symbols would at least show--as in your case.

I may have to recreate this application--it has so many problems and for someone like me who is barely getting started there are too many fires to put out during the learning process.


Thanks.
0 Kudos
vinayb
by
New Contributor III
Sorry my  code is not solution to ur problem ,  i have same problem as yours .But for your problem check from desktop tool the projection  sysrtem and spatialrefrence to use.
0 Kudos
JeffPace
MVP Alum
what type of geometry are you returning?

Your Subject says "points" but your code is using a fill symbol, which is polygon
0 Kudos
IrfanClemson
Occasional Contributor II
Sorry my  code is not solution to ur problem ,  i have same problem as yours .But for your problem check from desktop tool the projection  sysrtem and spatialrefrence to use.


Sorry, I don't understand. What should I tell the person who published the .mxd to the server to change and republish?
Thanks,
0 Kudos