ArcGIS js api 4.x手动构建FeatureLayer

创建map

var map = new Map({
   
   
    basemap: "dark-gray"
});

创建mapView

var view = new MapView({
   
   
    center: [-41.647, 36.41],
    zoom: 3,
    map: map,
    container: "viewDiv",
    popup: {
   
   
        defaultPopupTemplateEnabled: true
    }
});

创建符号样式symbol

var symbol = {
   
   
    type: "simple-marker", // autocasts as new SimpleMarkerSymbol()
    style: "square",
    color: "blue",
    size: "8px", // pixels
    outline: {
   
    // autocasts as new SimpleLineSymbol()
        color: [255, 255, 0],
        width: 3 // points
    }
};

构建字段列表fields

var fields = [{
   
   
        name: "ObjectID",
        alias: "ObjectID",
        type: "oid"
    },
    {
   
   
        name: "type",
        alias: "Type",
        type: "string"
    },
    {
   
   
        name: "name",
        alias: "Name",
        type: "string"
    }
]

构建图形数组Graphic

var graphics = points.map((point, index) => {
   
   
    return new Graphic({
   
   
        geometry: point,
        symbol: symbol,
        attributes: {
   
   
            ObjectID: index,
            type: "景点",
            name: "旅游景点" + index
        }
    });
});

创建FeatureLayer

const layer = new FeatureLayer({
   
   
    fields: fields,
    objectIdField: "ObjectID",
    geometryType: "point",
    spatialReference: {
   
    wkid: 3857 },
    source: graphics,
});

完整代码

<!DOCTYPE html>
<html>

<head>
    <meta charset
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值