初始化时使用
Layer
相关
点:PointLayer
,面:PolygonLayer
,线:LineLayer
点图层
let pointLayer
let list = [{
id: 'pointId',
name: 'pointName',
loc: [139.1545,40.2545],//点的经纬度
latitude: 40.2545,
longitude: 139.1545
}]//处理成这样的数组即可
pointLayer = new PointLayer({
zIndex: 3
})
.source(list, {
parser: {
type: 'json',
x: 'longitude',
y: 'latitude'
}
})
.shape('image01')//把点变成图片,图片名为image01
.size(20)
scene.addLayer(pointLayer)
面图层和线图层
let paramsData = {
type: 'FeatureCollection',
features: [
{
type: 'Feature',
id: e.id,
properties: {
name: e.name,
typeCode: e.areaType == 1 ? 'warningArea' : 'coreArea'//typeCode自定义,为了设置颜色
},
geometry: {
type: 'Polygon',
coordinates: []
}
}
]
}
let polygonLayer
let lineLayer
polygonLayer = new PolygonLayer({ zIndex: 2 })
.source(paramsData)
.color('typeCode', (e) => {//根据数组里的属性判断面的颜色
if (e == 'coreArea') {
return 'rgba(254, 34, 34, 0.15)'
}
if (e == 'warningArea') {
return 'rgba(255,142,21,0.18)'
}
if (e == 'point') {
return 'rgba(98,215,41,0.2)'
}
})
.shape('fill')
.active(true)
lineLayer = new LineLayer({
zIndex: 2
})
.source(paramsData)
.color('typeCode', (e) => {
if (e == 'coreArea') {
return 'rgba(254, 34, 34, 1)'
}
if (e == 'warningArea') {
return 'rgba(255,142,21,1)'
}
if (e == 'point') {
return 'rgba(98,215,41,1)'
}
})
// .active(true)
.size(0.5)
.style({
dashArray: [2, 2]
})
scene.addLayer(polygonLayer)
scene.addLayer(lineLayer)
ps:点图层和面/线图层需要传入的数据格式不一样