六、初始化图形和点

初始化时使用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:点图层和面/线图层需要传入的数据格式不一样

  • 7
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值