QueryTask for dynamicLayer

1219
6
Jump to solution
04-09-2014 12:28 PM
tomwang1
Occasional Contributor
Hi,

I am using ArcGISDynamicMapServiceLayer not FeatureLayer. I am wondering if there a way to query a dynamic layer while user clicks on map? Something likes:

var queryTask =  new QueryTask(dynamicMapServiceUrl + "/dynamicLayer", {
                "source": layerSource
              });
var query = new Query();
query.geometry = clickedMapPoint
0 Kudos
1 Solution

Accepted Solutions
JianHuang
Occasional Contributor III
Yes, the code snippet that you have should work.

View solution in original post

0 Kudos
6 Replies
JianHuang
Occasional Contributor III
Yes, the code snippet that you have should work.
0 Kudos
tomwang1
Occasional Contributor
Hi Huang Jian,

Nice to talk you again. I am not sure what I have be missing. I got this error message:

Uncaught TypeError: Object [object Object] has no method 'toJson'


If I change "dynamicMapServiceUrl/dynamicLayer" to "dynamicMapServiceUrl/2" to test my code, it works fine. Also the layerSource has no problem to draw on my map. Please advise!

function createQueryDataSourceLayer(mQuery) {
                  var m_queryDataSource = new esri.layers.QueryDataSource();
                  m_queryDataSource.geometryType = "polygon";
                  m_queryDataSource.oidFields = ["OBJECTID"];
                  m_queryDataSource.query = mQuery;
                  m_queryDataSource.spatialReference = new esri.SpatialReference({ wkid: 102100 });
                  m_queryDataSource.workspaceId = "myworkspace";
                  layerSource = new LayerDataSource();
                  layerSource.dataSource = m_queryDataSource;

                  return layerSource;
              }
0 Kudos
JianHuang
Occasional Contributor III
What is the layerSource got returned? Please post the json object.
0 Kudos
tomwang1
Occasional Contributor
I am not sure how to post json of the layerSource? it is an object. I can see from Chrome console, there are too many object in side.
0 Kudos
JianHuang
Occasional Contributor III
Or, maybe you can create a simple reproducible case and put it on jsfiddle.net.
0 Kudos
tomwang1
Occasional Contributor
Thanks Huang Jian,

It was my mistake.  QueryTask for dynamicLayer works fine with no problem!
0 Kudos