Pergunta

i am using arcgis javascript apis 3.5 and my code is

 function init() {           
        map = new esri.Map("mapDiv", {
            basemap: "streets",
            center: [-112.07102547942392, 46.75909704205151],
            zoom: 12,
            slider: false               
        });           


        var featureLayer = new esri.layers.FeatureLayer("http://abc/arcgis/rest/services/MTARNG/MapServer/0", {
            mode: esri.layers.FeatureLayer.MODE_SNAPSHOT,               
            outFields: ["*"]
        });

and for search in this layer i am using findtask. code is here

  findTask = new esri.tasks.FindTask("http://abc/arcgis/rest/services/MTARNG/MapServer");
        findParams = new esri.tasks.FindParameters();
        findParams.returnGeometry = true;
        findParams.layerIds = [0];
        findParams.searchFields = ["LOCATION", "PROJECT_PARCEL_NAME"];           
        findParams.searchText = "north portion";
        findTask.execute(findParams, showResults);
 function showResults(results) {

        var markerSymbol = new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_SQUARE, 10, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255, 0, 0]), 1), new dojo.Color([0, 255, 0, 0.25])); 
        map.graphics.clear();
        dojo.forEach(results, function (result) {
            var graphic = result.feature;               
            if (graphic.geometry != null) {
                switch (graphic.geometry.type) {
                    case "point":
                        graphic.setSymbol(markerSymbol);
                        break;                     
                }
            }
            map.graphics.add(graphic);
        });         
    }

So it is adding the features in map but in wrong place like in the image ![In the image features are in different place and graphics are in different place][1]

sory i dont have enough reputation point to post image? Please check my photo i have replace the image with my photo

I analysis then i came to know that result of wkid is responsible. i checked the wkid. my layers has wkid number "26912" and graphicslayer has wkid number 4326.

so what i will do, i just try to change the wkid but it is not working. i am working on right way or anything else i have to do.

thanks in advance.

Foi útil?

Solução

The graphics layer gets it's wkid from the map and the map (by default) sets it's wkid to that of the first raster layer you load, in your case, the base map. As you've seen this is 4326, which is used by ESRI for all of it's base maps (I think). You can't change the wkid of the map as raster layers (Tiled Layers) can't be reprojected.

One way to solve this is have the FindTask return it's results in the wkid you want, e.g. 4326. To do this, use the outSpatialReference of FindParameters:

findParams.outSpatialReference = new esri.SpatialReference({wkid:4326});;

or, take it straight from the map:

findParams.outSpatialReference = map.spatialReference;

The results should then be reprojected to 4326 by the server before being returned and so be in the correct system to add to the maps graphic layer.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top