2014-02-20 71 views
2

有人可以幫助我從ArcMap休息端點中獲取一些數據。我運行下面的jQuery的,但它是從restend點在arcGis休息端點上查詢

我的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); 

我已經把斷點var myAttribs = {};,並採取一看在queryTask_callback功能fSet對象。這將顯示字段名稱,因此它必須連接到EndPoint。但是當我看看數組是空的時候。

所以我的注意力轉移到查看ArcGIS REST服務目錄單擊頁面底部的查詢鏈接。我在輸出字段中輸入*,在where文本框中輸入OBJECTID> = 0,並返回224條記錄。其餘版本是10.21。

希望你能幫到

回答

3

你需要在你的查詢參數中設置定義和outFields的位置。

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); 

您可以查看文檔以獲取更多選項。 https://developers.arcgis.com/javascript/jsapi/query-amd.html

+0

感謝您的回覆。 ()函數updateGrid(fLayer){0} {0}}} 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); }' 這段代碼適用於您的建議,但是當我把 'queryParams.geometry = esri.geometry.webMercatorToGeographic(myMap.extent);'停止工作。但根據文件我想過濾使用範圍 – Easty

+0

我認爲你不需要做esri.geometry.webMercatorToGeographic的範圍。試試queryParams.geometry = myMap.extent; 。或嘗試將查詢的spatialReference設置爲4326,以告知您的查詢在地理座標中執行選擇。 – mchepurnoy

+0

唉,這是我沒有嘗試的唯一的事情!謝謝,現在工作。有趣的'queryParams.geometry = esri.geometry.webMercatorToGeographic(myMap.extent);'是直接出來的培訓手冊。從來沒有想過這可能是問題 – Easty