一般来说featurelayer是用来通过url来从arcigs server服务中来读取数据,但是也可以通过在客户端创建一个featurelayer.
例如:
//创建字段
var fileds=[
{name: "ObjectID",alias: "ObjectID",type: "oid"},
{name: "name",alias:"name",type: "string"},
{name: "population",alias: "population",type: "double"},
{name: "height",alias: "height",type: "double"}
];
//第一个要素
var pt=new Point(
{
longitude:103.266980,
latitude:24.7478,
spatialReference:{wkid:4326}
});
//第二个要素
var pt2=new Point(
{
longitude:99.158541,
latitude:25.12069,
spatialReference:{wkid:4326}
});
var sy=new SimpleMarkerSymbol(
{
color:"red"
});
//创建要素集合,用于创建要素
var features=[
{//每一个要素都是一个对象
geometry:pt,
attributes:{//该几何的属性字段和值
ObjectID: 1,//字段ObjectID
name:"石林",
population:200000.0,
height:5
}
},
{
geometry:pt2,
attributes:{//该几何的属性字段和值
ObjectID: 2,//字段ObjectID
name:"保山",
population:200000.0,
height:5}
}
];
//要素
var featurelayer=new FeatureLayer(
{
source:features,
id:"自定义要素图层",
fields:fileds,
objectIdField:"ObjectID",//图层中要素唯一的标识符
spatialReference:{wkid:4326},
geometryType:"point",//定义要素的类型
//renderer:render,
popupTemplate:{title:"{name}",content:"该地区的人口总数为:{population}"}
});