2019-12-31 19:17:29 +08:00
|
|
|
---
|
|
|
|
title: 城市建筑
|
|
|
|
order: 6
|
|
|
|
---
|
2020-11-21 14:05:59 +08:00
|
|
|
|
2020-11-21 03:51:18 +08:00
|
|
|
`markdown:docs/common/style.md`
|
2020-01-01 09:52:32 +08:00
|
|
|
|
2021-12-31 11:34:31 +08:00
|
|
|
## 简介
|
|
|
|
|
|
|
|
`CityBuildingLayer` 用于构建城市建筑 3D 模型, 展示城市建筑
|
|
|
|
|
2019-12-31 19:17:29 +08:00
|
|
|
## 使用
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
import { CityBuildingLayer } from '@antv/l7';
|
|
|
|
```
|
2020-01-01 09:52:32 +08:00
|
|
|
|
2022-01-06 14:30:29 +08:00
|
|
|
<img width="60%" style="display: block;margin: 0 auto;" alt="案例" src='https://gw.alipayobjects.com/mdn/rms_e7e1c6/afts/img/A*LoxeSZHuqXwAAAAAAAAAAAAAARQnAQ'>
|
2022-01-05 16:59:52 +08:00
|
|
|
|
2019-12-31 19:17:29 +08:00
|
|
|
### animate
|
2020-01-01 09:52:32 +08:00
|
|
|
|
2021-12-31 11:34:31 +08:00
|
|
|
是否开启动画效果, 仅支持`boolean` 或`enable: boolean` 配置项
|
2020-01-01 09:52:32 +08:00
|
|
|
|
2019-12-31 19:17:29 +08:00
|
|
|
```javascript
|
2020-01-01 09:52:32 +08:00
|
|
|
layer.animate(true);
|
2021-12-31 11:34:31 +08:00
|
|
|
|
|
|
|
layer.animatte({
|
|
|
|
enable: true,
|
|
|
|
});
|
2019-12-31 19:17:29 +08:00
|
|
|
```
|
2022-01-06 15:55:07 +08:00
|
|
|
|
|
|
|
✨ 在开启 animate 后默认会打开点亮窗户的动画
|
|
|
|
🌟 开启 animate 动画是打开扫光动画的前提
|
2019-12-31 19:17:29 +08:00
|
|
|
|
2020-01-01 09:52:32 +08:00
|
|
|
### style
|
|
|
|
|
|
|
|
- baseColor 楼房颜色,
|
|
|
|
- windowColor: 窗户颜色,
|
|
|
|
- brightColor: 点亮窗户颜色
|
2021-12-28 12:01:32 +08:00
|
|
|
- sweep: 圆形扫光扩散动画相关配置项
|
|
|
|
- enable: 是否开启扫光扩散
|
|
|
|
- sweepRadius: 扩散半径
|
|
|
|
- sweepCenter: 扩散中心店坐标
|
|
|
|
- sweepColor: 扩散颜色
|
|
|
|
- sweepSpeed: 扩散速度
|
2021-12-28 19:39:11 +08:00
|
|
|
- baseColor: 开启 sweep 时的基础颜色
|
2020-01-01 09:52:32 +08:00
|
|
|
|
|
|
|
其他 style 配置项同
|
2019-12-31 19:17:29 +08:00
|
|
|
|
2021-12-29 17:05:50 +08:00
|
|
|
[baselayer#style](../base#style)
|
2019-12-31 19:17:29 +08:00
|
|
|
|
2020-02-11 16:35:18 +08:00
|
|
|
## 自定义动画频率
|
|
|
|
|
2021-12-31 11:34:31 +08:00
|
|
|
自定义动画频率需要 关闭默认动画,通过 `setLight` 方法不断更新时间
|
2020-02-11 16:35:18 +08:00
|
|
|
|
|
|
|
### setLight(time)
|
|
|
|
|
|
|
|
参数
|
|
|
|
time : 时间 毫秒
|
|
|
|
|
2021-12-31 11:34:31 +08:00
|
|
|
```js
|
2021-12-31 16:01:16 +08:00
|
|
|
import { CityBuildingLayer, Scene } from '@antv/l7';
|
|
|
|
import { Mapbox } from '@antv/l7-maps';
|
2021-12-31 11:34:31 +08:00
|
|
|
|
2021-12-31 16:01:16 +08:00
|
|
|
const scene = new Scene({
|
|
|
|
id: 'map',
|
|
|
|
map: new Mapbox({
|
|
|
|
style: 'dark',
|
|
|
|
center: [121.507674, 31.223043],
|
|
|
|
pitch: 65.59312320916906,
|
|
|
|
zoom: 15.4,
|
|
|
|
minZoom: 15,
|
|
|
|
maxZoom: 18,
|
|
|
|
}),
|
|
|
|
});
|
2021-12-31 11:34:31 +08:00
|
|
|
const buildingLayer = new CityBuildingLayer();
|
|
|
|
buildingLayer.animate(false);
|
|
|
|
|
2021-12-31 16:01:16 +08:00
|
|
|
let i = 0;
|
|
|
|
function step() {
|
2022-01-06 14:30:29 +08:00
|
|
|
buildingLayer.setLight(i++);
|
2021-12-31 16:01:16 +08:00
|
|
|
scene.render();
|
|
|
|
requestAnimationFrame(step);
|
|
|
|
}
|
|
|
|
|
|
|
|
scene.on('loaded', () => {
|
|
|
|
step();
|
|
|
|
});
|
2021-12-31 11:34:31 +08:00
|
|
|
```
|
|
|
|
|
2019-12-31 19:17:29 +08:00
|
|
|
#### 完整代码
|
|
|
|
|
2020-01-01 09:52:32 +08:00
|
|
|
```javascript
|
2021-12-31 11:34:31 +08:00
|
|
|
import { Scene, CityBuildingLayer } from '@antv/l7';
|
|
|
|
import { GaodeMap } from '@antv/l7-maps';
|
|
|
|
|
|
|
|
const scene = new Scene({
|
|
|
|
id: 'map',
|
|
|
|
map: new GaodeMap({
|
|
|
|
style: 'dark',
|
|
|
|
center: [120.173104, 30.244072],
|
|
|
|
pitch: 70.41138037735848,
|
|
|
|
zoom: 17.18,
|
|
|
|
rotation: 2.24, // 358.7459759480504
|
|
|
|
minZoom: 14,
|
|
|
|
}),
|
|
|
|
});
|
|
|
|
|
|
|
|
scene.on('loaded', () => {
|
|
|
|
fetch('https://gw.alipayobjects.com/os/rmsportal/ggFwDClGjjvpSMBIrcEx.json')
|
|
|
|
.then((res) => res.json())
|
|
|
|
.then((data) => {
|
|
|
|
const layer = new CityBuildingLayer({
|
|
|
|
zIndex: 0,
|
|
|
|
});
|
|
|
|
layer.source(data);
|
|
|
|
scene.addLayer(layer);
|
|
|
|
});
|
|
|
|
});
|
2019-12-31 19:17:29 +08:00
|
|
|
```
|
2020-11-17 10:59:32 +08:00
|
|
|
|
2022-01-05 16:59:52 +08:00
|
|
|
[在线案例](../../../examples/gallery/animate#build_sweep)
|
2021-12-31 11:34:31 +08:00
|
|
|
|
2020-11-16 15:19:41 +08:00
|
|
|
`markdown:docs/common/layer/base.md`
|