mike.zheng

The new customer featurelayer (ploygon) could not display on the map. Thanks!

Discussion created by mike.zheng on May 31, 2011
Latest reply on Jun 1, 2011 by mike.zheng
Please see the code as below:

    <script type="text/javascript">
        dojo.require("dijit.layout.BorderContainer");
        dojo.require("dijit.layout.ContentPane");
        dojo.require("esri.map");
        dojo.require("esri.layers.FeatureLayer");
        dojo.require("esri.dijit.Popup");

        dojo.require("esri.arcgis.utils");
        dojo.require("esri.dijit.Scalebar");
        dojo.require("esri.dijit.editing.Editor-all");
        dojo.require("esri.tasks.geometry");
        var gsvc = null;

        var map;
        var featureLayer;
        var resizeTimer;

        var webmap;

        function init() {

            webmap = "da8e773cb68149a39e06f706c6d7cdb2";
            var itemDeferred = esri.arcgis.utils.getItem(webmap);

            itemDeferred.addCallback(function (itemInfo) {

                var initExtent = new esri.geometry.Extent({ "xmin": -12734442.894989174, "ymin": 4942199.239293063, "xmax": -5342676.5117014535, "ymax": 8459525.5328628, "spatialReference": { "wkid": 102100} });


                //create a popup to replace the map's info window
                var popup = new esri.dijit.Popup(null, dojo.create("div"));
                map = new esri.Map("map", {
                    extent: initExtent,
                    infoWindow: popup
                });

                dojo.place(popup.domNode, map.root);

                var basemap = new esri.layers.ArcGISTiledMapServiceLayer("http://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer");
                map.addLayer(basemap);

                                dojo.connect(map, "onLayersAddResult", function (results) { requestPhotos(itemInfo); });
                                map.addLayers([featureLayer]);

                //create a feature collection for the flickr photos
                var featureCollectionPolygon = {
                    "layerDefinition": null,
                    "featureSet": {
                        "features": [],
                        "geometryType": "esriGeometryPolygon"
                    }
                };
                featureCollectionPolygon.layerDefinition = {
                    "geometryType": "esriGeometryPolygon",
                    "objectIdField": "ObjectID",
                    "drawingInfo": {
                        "renderer": {
                            "type": "simple",
                            "symbol": {
                                "type": "esriSFS",
                                "style": "esriSFSSolid"
                            }
                        }
                    },
                    "fields": [{
                        "name": "ObjectID",
                        "alias": "ObjectID",
                        "type": "esriFieldTypeOID"
                    }, {
                        "name": "description",
                        "alias": "Description",
                        "type": "esriFieldTypeString"
                    }, {
                        "name": "imagelink",
                        "alias": "imagelink",
                        "type": "esriFieldTypeString"
                    }, {
                        "name": "title",
                        "alias": "Title",
                        "type": "esriFieldTypeString"
                    }]
                };

                //define a popup template
                var popupTemplatePolygon = new esri.dijit.PopupTemplate({
                    title: "{title}",
                    description: "{description}"
                });

                //create a feature layer based on the feature collection
                featureLayerPolygon = new esri.layers.FeatureLayer(featureCollectionPolygon, {
                    id: 'Building Information',
                    infoTemplate: popupTemplatePolygon
                });

                //associate the features with the popup on click
                dojo.connect(featureLayerPolygon, "onClick", function (evt) {
                    map.infoWindow.setFeatures([evt.graphic]);
                    map.infoWindow.show(evt.mapPoint);
                });

                dojo.connect(map, "onLayersAddResult", function (results) { requestPolygon(itemInfo); });

                map.addLayers([featureLayerPolygon]);

                dojo.connect(map, 'onLoad', function (theMap) {
                    dojo.connect(dijit.byId('map'), 'resize', function () { //resize the map if the div is resized
                        clearTimeout(resizeTimer);
                        resizeTimer = setTimeout(function () {
                            map.resize();
                            map.reposition();
                        }, 500);
                    });
                });

            });

        }

        function requestPolygon(itemInfo) {
            var polygonSymbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_DOT, new dojo.Color([151, 249, 0, .80]), 3), new dojo.Color([151, 249, 0, 0.45]));

            var polygon = new esri.geometry.Polygon({
                "rings": [
            [
              [-4226661.916056009, 8496372.808143634],
              [-3835304.3312360067, 8731187.359035634],
              [-2269873.991956003, 9005137.668409634],
              [-4304933.433020009, 7635386.121539632],
              [-4304933.433020009, 7674521.880021632],
              [-4226661.916056009, 8496372.808143634]
            ]
          ],
                "spatialReference": {
                    "wkid": 102100
                }
            });

            features.push(new esri.Graphic(polygon, polygonSymbol));

            featureLayerPolygon.applyEdits(features, null, null);
        }

        dojo.ready(init);

    </script>

Outcomes