add_featurelayer_to_map

时间:2024-05-12 13:07:44

var jsonFS = {
"geometryType": "esriGeometryPolygon",
"features": [
{
"attributes": {
"Name": "Polygon2", // "Point2",
"OBJECTID": 2

},
"geometry": {
"rings": [
[[117.008726, 30.931672], [117.009635, 30.930947], [117.008825, 30.930337], [117.007929, 30.931062]]
]
}
}
],
"spatialReference": {
"wkid": 4326
}
};
var fs = new FeatureSet(jsonFS);
var layerDefinition = {
"displayFieldName": "Name",
"geometryType": "esriGeometryPolygon",
"spatialReference": {
"wkid": 4326
},
"fields": [
{
"name": "OBJECTID",
"type": "esriFieldTypeOID",
"alias": "OBJECTID"
},
{
"name": "Name",
"type": "esriFieldTypeString",
"alias": "Name",
"length": 10
}
]
}

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

featureLayer = new FeatureLayer(featureCollection);

symbol = new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID, new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID,
     new Color([112, 112, 112]), 1), new Color([236, 136, 136, 0.75]));
var renderer = new SimpleRenderer(symbol);
featureLayer.setRenderer(renderer);

map.addLayers([featureLayer]);