2

Can Someone help me get some data out of an ArcMap Rest EndPoint. I am running the jquery below but it is returning no data from the restend point

My Jquery:

        dojo.require("esri.map");
dojo.require("esri.dijit.OverviewMap");
dojo.require("dijit.form.CheckBox");
dojo.require("esri.layers.FeatureLayer");
dojo.require("dojox.grid.DataGrid");
dojo.require("dojo.data.ItemFileReadStore");
dojo.require("esri.tasks.query");
dojo.require("esri.dijit.Measurement");
dojo.require("esri.dijit.Scalebar");

var myMap;

function init() {

    var initialExtent = new esri.geometry.Extent({"xmin":455248.7328447895,"ymin":404516.307641385,"xmax":532048.7328447895,"ymax":484516.307641385,"spatialReference":{"wkid":27700}});
    myMap = new esri.Map("mainMap", {extent:initialExtent});

    // myMap.infoWindow.resize(210,95);
    var baseLayer = new esri.layers.ArcGISTiledMapServiceLayer("http://g*****************.uk/ArcGIS/rest/services/ProxyMaps/OSBaseMap/MapServer");
    myMap.addLayer(baseLayer);

    var imageParameters = new esri.layers.ImageParameters();
    imageParameters.layerIds = [5];
    imageParameters.layerOption = esri.layers.ImageParameters.LAYER_OPTION_SHOW;

    layer = new esri.layers.ArcGISDynamicMapServiceLayer("http://*************/arcgis/rest/services/New_ForwardPlanning/MapServer", {"imageParameters":imageParameters});

    myMap.addLayer(layer);

    var featureLayer1 = new esri.layers.FeatureLayer("http://************/arcgis/rest/services/New_ForwardPlanning/MapServer/0",{
        mode: esri.layers.FeatureLayer.MODE_ONDEMAND,
        id: "sd_neighborhoods",
        outFields: ["*"],
        opacity:0.6
    }); 

    dojo.connect(myMap, 'onLoad', function(myMap) {

        myMap.addLayer(featureLayer1);
        initGrid();

    });


   }


   function initGrid() {
    dojo.connect(myMap, 'onExtentChange', function() {
        console.log("myMap zoom = " + dojo.toJson(myMap.getZoom()));
        console.log("myMap extent = " + dojo.toJson(myMap.extent.toJson()));
        updateGrid(myMap.getLayer("sd_neighborhoods"));
    });
}

function updateGrid(fLayer) {
    var queryParams = new esri.tasks.Query();
    queryParams.geometry = esri.geometry.webMercatorToGeographic(myMap.extent);
    queryParams.spatialRelationship = esri.tasks.Query.SPATIAL_REL_INTERSECTS;
    fLayer.queryFeatures(queryParams, queryTask_callback);
}

function queryTask_callback(fSet) {
    var myAttribs = {};
    var myItems = [];
    //begin for-loop to calculate myAtttribs objects and populate myItems
    for (var i=0, il=fSet.features.length; i<il; i++) {
        myAttribs = {"NAME":fSet.features[i].attributes.NAME, "ownPct":fSet.features[i].attributes.URL};
        myItems.push(myAttribs);
    }


    //end for-loop
    var myData = { items: myItems };
    var myStore = new dojo.data.ItemFileReadStore({ data: myData });
    myGrid.setStore(myStore);
    myGrid.resize();


}

      dojo.ready(init);

I have put a breakpoint on var myAttribs = {}; and taken a look at the fSet object in the queryTask_callback function. This displays the field names so it must be connecting to the EndPoint. But when I look at the features the array is empty.

So my attention moved to looking at the ArcGIS REST Services Directory Clicked on the Query link at the bottom of the page. I entered * in the output fields and OBJECTID >=0 in the where text box and it returns 224 records. The rest version is 10.21.

Hope you can help

Vikash Pandey
  • 5,407
  • 6
  • 41
  • 42
Easty
  • 387
  • 1
  • 6
  • 17

1 Answers1

3

You need to set where definition and outFields in your query parameters.

function updateGrid(fLayer) {
var queryParams = new esri.tasks.Query();
queryParams.geometry = esri.geometry.webMercatorToGeographic(myMap.extent);
//your specific query here
queryParams.where = "1=1"; 
queryParams.outFields = "*";

queryParams.spatialRelationship = esri.tasks.Query.SPATIAL_REL_INTERSECTS;
fLayer.queryFeatures(queryParams, queryTask_callback);

You can check documentation for more options. https://developers.arcgis.com/javascript/jsapi/query-amd.html

mchepurnoy
  • 158
  • 7
  • Thanks for your reply. `function updateGrid(fLayer) { var queryParams = new esri.tasks.Query(); //queryParams.geometry = esri.geometry.webMercatorToGeographic(myMap.extent); queryParams.where = "1=1"; queryParams.outFields = "*"; //queryParams.spatialRelationship = esri.tasks.Query.SPATIAL_REL_INTERSECTS; fLayer.queryFeatures(queryParams, queryTask_callback); }` This code work from your suggestion but when I put in `queryParams.geometry = esri.geometry.webMercatorToGeographic(myMap.extent);` it stops working. But as per the doc I wan to filter using the extent – Easty Feb 21 '14 at 15:36
  • I think that you don't need to do esri.geometry.webMercatorToGeographic on extent. Try queryParams.geometry = myMap.extent; . Or try set spatialReference of your query to 4326, to tell your query perform selection in geographic coordinates. – mchepurnoy Feb 23 '14 at 13:58
  • Aahh that's about the only thing I did not try! Thanks that has worked now. Funny `queryParams.geometry = esri.geometry.webMercatorToGeographic(myMap.extent);` is straight out of the training manual. Never thought that could be the problem – Easty Feb 24 '14 at 11:58