AnsweredAssumed Answered

Simple example to add a polygon to a map?

Question asked by jsirianni@allcovered.com on Dec 7, 2015
Latest reply on Apr 29, 2016 by thebillcarr

Is there a simple example on how to add a polygon to a map? (Web API)

I'm trying to add a polygon to a map and fill it in.

 

Currently I have:

<script>

        var map;

 

        require([

          "esri/map",

          "esri/geometry/Extent",

          "esri/layers/FeatureLayer",

          "esri/symbols/SimpleLineSymbol",

          "esri/symbols/SimpleFillSymbol",

          "esri/symbols/TextSymbol",

          "esri/renderers/SimpleRenderer",

          "esri/geometry/Polygon",

          "esri/layers/GraphicsLayer",

          "esri/layers/LabelClass",

          "dojo/_base/Color",

          "dojo/domReady!"

        ], function(Map, Extent, FeatureLayer, SimpleLineSymbol, SimpleFillSymbol,

          TextSymbol, SimpleRenderer, Polygon, GraphicsLayer, LabelClass, Color) {

            map = new Map("map", {

                showLabels: true, //very important that this must be set to true!

                basemap: "streets",

                center: [-79.746933, 40.446949],

                zoom: 8

        });

            var graphicLayer = new GraphicsLayer();

            var bCounty = new Polygon(loadBCounty());         

         

            map.addLayer(graphicLayer);

            graphicLayer.add(bCounty);

 

 

 

 

        function loadBCounty()

        {

            return [[-80.395815,40.477370],

          [-80.394242,40.477313],

          [-80.394242,40.477313],

          [-80.394050,40.477306],

          [-80.362057,40.477539],

          [-80.164173, 40.978097],

          [-80.164226, 40.979473],

          [-80.164877, 40.995214],

          [-80.165292, 41.000474],

          [-80.161159, 41.004532],

          [-80.154676, 41.010891],

          [-80.137160, 41.028076],

          [-80.460466, 40.477488],

          [-80.460466, 40.477488],

          [-80.448980, 40.477701],

          [-80.438175, 40.477783],

          [-80.395815, 40.477370]

]

        }

</script>

Outcomes