3

This one is strange: i have a map that takes features from a gp service and turns them into a graphics layer. If i add the layer, for some reason the map's spatialreference changes from 4686 to 4326, if i comment that line, the change does not happen.

The features exposed by the service come in 4686, below is the relevant part

Picture taken from the rest page

Even worse, the table where data is stored, was created via arccatalog wid wkid 4686. So, i have absolutely no idea where this 4326 is coming from.

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"/>
    <title>test</title>

    <link rel="stylesheet" href="http://js.arcgis.com/3.12/dijit/themes/nihilo/nihilo.css"> 
    <link rel="stylesheet" href="http://js.arcgis.com/3.12/esri/css/esri.css">                  

    <script type="text/javascript">dojoConfig = {parseOnLoad: true};</script>
    <script src="http://js.arcgis.com/3.12/"></script>

    <script >   
    var mapa;
    var gp;

    require([
    "esri/map",         
    "dojo/parser",  
    "esri/dijit/Print",
    "dijit/Toolbar",
    "dijit/form/Button",
    "dojo/dom",
    "dojo/dom-construct",
    "esri/layers/FeatureLayer",
    "esri/tasks/Geoprocessor",
    "esri/tasks/FeatureSet",
    "esri/layers/ArcGISTiledMapServiceLayer",
    "esri/layers/ArcGISDynamicMapServiceLayer",
    "esri/tasks/query", 
    "esri/tasks/QueryTask",
    "dojo/domReady!"                                 
    ], 
    function(Map, Extent, Button, Toolbar, parser, Print, FeatureLayer, Geoprocessor, Query, QueryTask) {
        mapa = new Map("map", {
        extent:  new esri.geometry.Extent(-82.00, 4.50, -66.00, 14.00, new esri.SpatialReference({ wkid:4686 })),
        zoom: 8,        
        slider: false,
        spatialReference: { wkid: 4686 }
        });         


        gp = new esri.tasks.Geoprocessor("...");
        gp.setOutputSpatialReference({wkid:4686});
        gp.submitJob({}, completeCallback, statusCallback);
        console.log(mapa);
    });

    function completeCallback(jobInfo){                 
        gp.getResultData(jobInfo.jobId, "...", function(results, messages) {
            var symbol_ = new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_SQUARE, 10, esri.symbol.SimpleLineSymbol.STYLE_SOLID,  new esri.Color([255,0,0]) );

            var gl = new esri.layers.GraphicsLayer();

            for (var i = 0; i < results.value.features.length; i++) {
                if (results.value.features[i].geometry != null) {                   
                    results.value.features[i].setSymbol(symbol_);
                    console.log(results.value.features[i]);
                    gl.add(results.value.features[i]);
                }
            }
            mapa.addLayer(gl); // <-- THIS IS THE PROBLEMATIC LINE
            console.log(gl);            
        });
    }

    function statusCallback(jobInfo) {      
    }

    </script>
</head>

<body>
<div id="map"></div>

</body>
</html>
3
  • Can you paste a feature Json that comes back Jan 21, 2015 at 22:59
  • What if you do not add graphics and just add the layer? Is it still a problem? Jan 22, 2015 at 3:12
  • @AamirSuleman hi aamir, yes, if i add an empty layer the problem persists (commenting the whole for). As for the json, since i am working with sensible info i cannot paste it online. however i can tell you that it seems all right, it has all the fields, it has all the data it should have, the geometries for every feature are right. thanks Jan 22, 2015 at 15:02

1 Answer 1

1

4686 works for FeatureLayers. Don't add GraphicsLayer just by itself. You must add a base layer.

Try this example to test a map with just a FeatureLayer, using the map extent in the question

http://developers.arcgis.com/javascript/sandbox/sandbox.html?sample=fl_no_basemap

Change the value of bounds like this

var bounds = new esri.geometry.Extent(-82.00, 4.50, -66.00, 14.00, new esri.SpatialReference({ wkid:4686 }));

The FeatureLayer is projected to 4686

But, in your case you must add a base layer.

var gl = new esri.layers.GraphicsLayer();
var dynamicMapServiceLayer = new esri.layers.ArcGISDynamicMapServiceLayer("http://sampleserver6.arcgisonline.com/arcgis/rest/services/WorldTimeZones/MapServer");

map.addLayers([dynamicMapServiceLayer,gl]);

And your projection will stick to 4686

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.