how to display a featurelayer's simbology in right place??

1201
2
12-29-2016 11:20 AM
michellechristmas1
New Contributor II

have this code, when you run the code the map is centered at -77.044180,  38.853682, which is DC I got the lat long from google. When you do a right click and see what's here. Anyways. I have created a fake featurelayer by  defining a featureSet and then a FeatureCollection from a json object. The map works the only thing is that the symbology shows up somewhere in Pitsburgh and New Haven and I do not know why???, not sure how I can make it show in DC. You can see the two read circles when you zoom out to the world extent.  Can someone tell me where my logic is failing??? I got this code from some other exapmple and just modified it.

<!DOCTYPE html> 
< html> 
< head> 
    <meta charset="utf-8"> 
    <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no"> 
    <title>FeatureLayer</title> 
< link rel="stylesheet" href="https://js.arcgis.com/3.19/esri/css/esri.css">
  
   
    <style> 
        html, body, #map { 
            padding: 0; 
            margin: 0; 
            height: 100%; 
            width: 100%; 
        } 
    </style>
 <script src="http://js.arcgis.com/3.19/"></script>   

    <script> 
        require([ 
            "esri/map", "esri/symbols/SimpleMarkerSymbol", "esri/Color", "esri/renderers/SimpleRenderer", 
            "esri/tasks/FeatureSet", "esri/layers/FeatureLayer", "esri/basemaps",
            "dojo/domReady!" 
        ], function( 
            Map, SimpleMarkerSymbol, Color, SimpleRenderer, 
            FeatureSet, FeatureLayer 
        ) { 

  //My example was from https://community.esri.com/thread/171775


            var map = new Map("map", { 
  basemap: "osm",
  //center: [-123.141608, 49.245291],
 center: [-77.044180,  38.853682],
 zoom: 13
            }); 

                     map.on('load', function() { 
                    var jsonFS = {
  "displayFieldName": "Name",
  "fieldAliases": {
    "Name": "Name"
  },
  "geometryType": "esriGeometryPoint",
  "spatialReference": {
    "wkid": 102100
  },
  "fields": [{
    "name": "Name",
    "type": "esriFieldTypeOID",
    "alias": "Name"
  }],
  "features": [{
    "attributes": {
      "Name": "1"
    },
    "geometry": {
      "x": -8919439.31450887,
      "y": 4928270.761925456
 
 
    }
  }, {
    "attributes": {
      "Name": "2"
    },
    "geometry": {
      "x": -8155495.379532158,
      "y": 5075380.311392084
    }
  }]
};

                var fs = new FeatureSet(jsonFS);


    var layerDefinition = {
    "geometryType": "esriGeometryPoint",
    "drawingInfo": {
      "renderer": {
        "type": "simple",
        "symbol": {
          "type": "esriPMS",
          "style": "esriSMSSquare",
          "color": [76, 115, 0, 255],
          "width": 50,
          "height": 50
        }
      }
    },
    "fields": [{
      "name": "Name",
      "type": "esriFieldTypeOID",
      "alias": "Name"
    }]
  };

                var featureCollection = { 
                    layerDefinition : layerDefinition, 
                    featureSet : fs 
                }; 

                featureLayer = new FeatureLayer(featureCollection); 
                var symbol = new SimpleMarkerSymbol().setColor(new esri.Color([255,0,0,0.5])); 
                var renderer = new SimpleRenderer(symbol); 
                featureLayer.setRenderer(renderer); 

                map.addLayer(featureLayer); 
            }); 

        }); 
        </script> 
    </head> 

    <body class='claro'> 
        <div id="map" ></div> 
    </body> 

</html>


Tags (1)
0 Kudos
2 Replies
RobertScheitlin__GISP
MVP Emeritus

Michelle,

   The app is doing exactly what it is suppose to do the XY values that you are feeding to the FeatureLayer are specified in wkid 102100 (web mercator), so they are suppose to be in Penn Center West, PA and just off of Timbermill Rd in Newtown, CT. Where are you expecting these points to be?

0 Kudos
michellechristmas1
New Contributor II

i figured it out added a map.on click event to get the points so to be able to modify the feature x and y values on the fake feature layer

var jsonFS = {
"displayFieldName": "Name",
"fieldAliases": {
"Name": "Name"
},
"geometryType": "esriGeometryPoint",
"spatialReference": {
"wkid": 102100
// "wkid":4326
},
"fields": [{
"name": "Name",
"type": "esriFieldTypeOID",
"alias": "Name"
}],
"features": [{
"attributes": {
"Name": "1"
},
"geometry": {
// "x": -8919439.31450887,
// "y": 4928270.761925456

"x":-8576217.915386291,
"y":4700791.720846395


}
}, {
"attributes": {
"Name": "2"
},
"geometry": {
// "x": -8155495.379532158,
// "y": 5075380.311392084

"x":-8576213.138072025,
"y":4700371.317190832

}
}]

these are the new values

map.on("click", function(e){
var mapPoint = e.mapPoint;
console.log(mapPoint);
});

0 Kudos