I'm working with arcGIS javascript api 3.12.

My current call for displaying the feature layer is as follows:

var recLayer = new FeatureLayer("http://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/3" ,{
  infoTemplate: recParkTemplate,
  outFields: ["STATE_NAME"]

However, instead of plotting the polygon on the map as this is an esriGeometricPolygon. I would rather have it plot on the map like a esriGeometryPoint. I know this method in getting the specific polygon's centroid:


What I have done so far is something like this when the map has finished loading:

recLayer.on("graphic-add", function(graphic) {
        console.log("\n\n" + recLayer.graphics.length);

What this does is give me the graphics object as they are loaded. From here I figure I can manipulate them into displaying the centroid alone. However, this is not working as expected where I'd think it would be


This comes with an error. From there I'd like to change the graphic to a plot point and then have a pin display at the center of the polygon.

Do I have the right approach? Is there something I'm missing?

Here is the current site if you would like to take a look at it: http://joshferrell.net/ece_project/

1 Answer 1


Set the geometry for the graphic using the setGeometry method. Also set the symbol on the graphic OR you may change the renderer (using marker symbols) on the featureLayer when the featureLayer loads.

var pointSymbol = new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_SQUARE, 10, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID,   new esri.Color([255,0,0]), 1),   new esri.Color([0,255,0,0.25]));

recLayer.on("graphic-add", function(graphic) {

    console.log("\n\n" + fl.graphics.length);
    //get centroid
    var centroid = graphic.graphic.geometry.getCentroid();
    //set geometry for the graphic
    //set symbol for the graphic


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.