1. AreaLayer

Extends: Layer

1.1. 初始化 new AreaLayer(options)

矢量面图层,可实现单个或批量面状要素数据的添加、移除和定位等操作

Param Type Default Description
options Object

包含以下参数的Object对象

[options.name] String true

图层名称

[options.show] Boolean

是否显示

[options.customGroupId] String

自定义分组的ID

Example

let geomap = new BOSGeo.GeoMap('bosgeoContainer');
let areaLayer = geomap.layerManager.createLayer(BOSGeo.LayerType.AREA, 'testarea');

1.2. 属性

属性名 Type Default Description
show Boolean

是否显示图层

landMaterial CustomAreaMaterial BOSGeo.CustomAreaMaterial.ColorMaterial

areaLayer中所有非批量面要素的底面区域材质统一设置

wallMaterial CustomAreaMaterial BOSGeo.CustomAreaMaterial.StripMaterial

areaLayer中所有非批量面要素的墙体材质统一设置

Example

//example1.设置默认圆点
areaLayer.wallMaterial = BOSGeo.CustomAreaMaterial.DotMaterial;
//example2.设置指定颜色
areaLayer.landMaterial = new BOSGeo.CustomAreaMaterial({
    color: BOSGeo.Color.fromCssColorString("#67ADDF")
});
//example3.设置默认棋盘材质
areaLayer.wallMaterial = BOSGeo.CustomAreaMaterial.CheckboardMaterial;
//example4.设置指定颜色
areaLayer.wallMaterial = new BOSGeo.CustomAreaMaterial({
    color: BOSGeo.Color.BLUE
});

1.3. 方法

1.3.1. areaLayer.add(options) ⇒ Area

添加面对象(适用于单个数据的添加管理,不适用于批量面的一次性加载)

Param Type Default Description
options Object

包含以下属性的对象:

options.positions Array.<(Array.<Number>|Cartesian3)>

必传经纬度与高程坐标数组。

[options.clampToGround] Boolean false

是否贴地

[options.landMaterial] AreaMaterialConfig

特殊面材质参数, 选填。

[options.extrudedHeight] Number

拉伸高度,相对于底面而言,clampToGround为false时起效

[options.bottomHeight] Number 0.0

底面高度(距离海平面的高度),clampToGround为false时起效,用于底面质心高度设置

Example

let areaLayer = layerManager.createLayer(BOSGeo.LayerType.AREA, "面图层");
const landMaterial = BOSGeo.AreaMaterialConfig.DOT; //获取一套材质配置参数模板
landMaterial.lightColor = '#ff0000'; //修改材质配置参数     * 
areaLayer.add({
    positions: [[113, 24, 0], [112, 25, 0], [112, 20, 0]],
    landMaterial: landMaterial
});

1.3.2. areaLayer.addCircle(options) ⇒ Area

添加圆(适用于单个数据的添加管理,不适用于批量面的一次性加载)

Kind : instance method of AreaLayer Returns : Object -

包含面要素和圆的关键几何信息的对象

Param Type Default Description
options Object

包含以下属性的对象:

options.center Array.<Number>

圆的中心点,可以是三维笛卡尔坐标,也可以是包含经度、纬度和高度的坐标数组

options.radius Number

圆的半径

[options.clampToGround] Boolean false

是否贴地

[options.landMaterial] CustomAreaMaterial BOSGeo.CustomAreaMaterial.ColorMaterial

面自定义材质

[options.extrudedHeight] Number

拉伸高度,相对于底面而言,clampToGround为false时起效

[options.bottomHeight] Number 0.0

底面高度(距离海平面的高度),clampToGround为false时起效,用于底面质心高度设置

Example

const dotMaterial = BOSGeo.CustomAreaMaterial.DotMaterial;
var area = areaLayer.addCircle({
    center: [113, 24, 0],
    radius: 120,
    landMaterial: dotMaterial
});

1.3.3. areaLayer.remove(area, [onlyWall])

移除非批量添加的面对象(仅限于单个对象的移除,无法移除批量对象@see removeBatchedArea)

Param Type Default Description
area Area

区域

[onlyWall] Boolean false

仅移除墙体,不移除底面区域

1.3.4. areaLayer.removeAll[onlyWalls])

移除所有非批量加载面要素及其墙体或仅移除其墙体

Param Type Default
[onlyWalls] Boolean false

1.3.5. areaLayer.zoomToLayer(callback)

缩放至本图层

Param Type Description
callback function

回调函数

1.3.6. areaLayer.destroy()

销毁本图层

1.3.7. areaLayer.loadGeoJson(options) ⇒ Primitive | GroundPrimitive

通过GeoJson对象批量添加面要素对象

Kind : instance method of AreaLayer

Returns : Primitive | GroundPrimitive -

primitive 批量实例化对象,该图元有自定义属性primitiveId可用于定位和移除

Param Type Default Description
options Object

包含以下属性的对象:

options.geojson Object

geojson对象(目前仅支持EPSG:4326坐标系,并只支持到要素和要素集合层级)

[options.clampToGround] Object false

面要素是否贴地

[options.colorTable] Object {} 颜色对照表,key是要素的属性表达式如"${Floor}>10" value是满足该表达式的颜色值类型为BOSGeo.Color, 注意:颜色表达式key的写法与Cesium.ConditionsExpression类似,详情参考:3DTiles-Styles
[options.defaultColor] Color BOSGeo.Color.RED.withAlpha(0.8)

默认颜色值,如不设置colorTable或者colorTable中关键属性值无法在properties中找到时要素一致使用该颜色

[options.height] Number 0.1

平面底面高程,clampToGround或perPositionHeight为true时无效

[options.perPositionHeight] Boolean false

是否每个顶点高度一致,clampToGround为true时无效

options.featureKey String

要素标识属性名称,不指定或者指定要素值不唯一则无法进行要素定位(此时要素位置信息会保存在图元id属性中)

Example

var batchedPrimitive;
// 移除上个批量图元集合
batchedPrimitive && areaLayer.removeBatchedArea(batchedPrimitive.primitiveId);
BOSGeo.Resource.fetchJson({
    url: 'http://bosgeo.boswinner.com/geoData/geojson/shenzhen_part11492.geojson'
}).then((res) => {
    batchedPrimitive = areaLayer.loadGeoJson({
        geojson: res,
        clampToGround: false,
        height: 10,
        defaultColor: BOSGeo.Color.YELLOW.withAlpha(.2),
        colorTable: {
            "${Floor} > 20": BOSGeo.Color.YELLOW,
            "${Floor} > 10": BOSGeo.Color.RED,
            "${Floor} >= 5": BOSGeo.Color.BLUE,
            "true": BOSGeo.Color.GREEN
        }
    });
    // 定位到当前添加的批量图元集合
    areaLayer.flyToBatchedArea(batchedPrimitive.primitiveId);
});

1.3.8. areaLayer.loadInBatch(options) ⇒ Primitive | GroundPrimitive

批量加载面要素对象

Kind : instance method of AreaLayer

Returns : Primitive | GroundPrimitive -

primitive 批量实例化对象,该图元有自定义属性primitiveId可用于定位和移除

Param Type Default Description
options Object

包含以下参数的Object对象:

options.positions Array.<Array.<Array.<Cartesian3>>>

批量面要素顶点坐标集, (数组最外层为要素,最内层为要素的点坐标集, 中间层为面轮廓及洞顶点) 注意:(1)单个要素中点个数必须大于2,否则要素会被跳过(2)经纬度坐标转换可参考BOSGeo.Cartesian3.fromDegreesArray和fromDegreesArrayHeights

[options.clampToGround] Object false

面要素是否贴地

[options.propertiesList] Array.<Object> []

批量面要素的属性集合,与positions外层对应, 注意:(1)不设置则无法进行要素个性化展示、且不便于加载后的查询(2)不建议把查询信息完全放在展示面要素中,只在里面放一下关键信息如id或个性化展示相关属性

[options.colorTable] Object {} 颜色对照表,key是要素的属性表达式如"${Floor}>10" value是满足该表达式的颜色值类型为BOSGeo.Color, 注意:颜色表达式key的写法与Cesium.ConditionsExpression类似,详情参考: 3DTiles-Styles
[options.defaultColor] Color BOSGeo.Color.RED.withAlpha(0.8)

默认颜色值,如不设置colorTable或者colorTable中关键属性值无法在properties中找到时要素一致使用该颜色

[options.height] Number 0.1

平面离地高度,clampToGround或perPositionHeight为true时无效

[options.perPositionHeight] Boolean false

是否每个顶点高度一致,clampToGround为true时无效

options.featureKey String

要素标识属性名称,不指定或者指定要素值不唯一则无法进行要素定位(此时要素位置信息会保存在图元id属性中)

Example

// 将polygon的geometry坐标点转化为Array.<Array.<Cartesian3>>
function transformPolygonCoordinates(coordinates) {
    let outline = coordinates[0];
    const outlineCoords = [];
    outline.forEach((point) => {
        outlineCoords.push(BOSGeo.Cartesian3.fromDegrees(point[0], point[1]));
    });
    // 洞
    const holes = [];
    for (let j = 1, geometryNumber = coordinates.length; j < geometryNumber; j++) {
        outline = coordinates[j];
        const hole = [];
        outline.forEach((point) => {
            hole.push(BOSGeo.Cartesian3.fromDegrees(point[0], point[1]));
        });
        holes.push(hole);
    }
    return [outlineCoords, ...holes];
}

// 加载Geojson
BOSGeo.Resource.fetchJson({
    url: 'http://bosgeo.boswinner.com/geoData/geojson/shenzhen_part11492.geojson'
}).then((res) => {

    const {features} = res;

    const propertiesList = [];
    const featurePositions = [];

    features.forEach((feature) => {
        const {geometry, properties} = feature;
        const {coordinates, type} = geometry;
        switch (type) {
            case 'Polygon':
                featurePositions.push(transformPolygonCoordinates(coordinates));
                propertiesList.push(properties);
                break;
            case 'MultiPolygon':
                coordinates.forEach((polygon) => {
                    featurePositions.push(transformPolygonCoordinates(polygon));
                    propertiesList.push(properties);
                });
                break;
        }
    });

    var batchedPrimitive = areaLayer.loadInBatch({
        positions: featurePositions,
        propertiesList: propertiesList,
        clampToGround: false,
        height: 10,
        defaultColor: BOSGeo.Color.YELLOW.withAlpha(.2),
        colorTable: {
            "${Floor} > 20": BOSGeo.Color.YELLOW,
            "${Floor} > 10": BOSGeo.Color.RED,
            "${Floor} >= 5": BOSGeo.Color.BLUE,
            "true": BOSGeo.Color.GREEN
        }
    });
    areaLayer.flyToBatchedArea(batchedPrimitive.primitiveId);
});

1.3.9. areaLayer.removeBatchedArea(primitiveId) ⇒ Boolean

移除批量区域

Kind : instance method of AreaLayer

Returns : Boolean -

true表示删除成功,false 表示目前图层内不存在批量区域或移除失败

See : loadGeoJson

Param Type Description
primitiveId String

批量图元id属性值--primitiveId

1.3.10. areaLayer.removeAllAreas([onlyWalls])

移除所有非批量加载面要素及其墙体或仅移除其墙体

Kind : instance method of AreaLayer

Param Type Default
[onlyWalls] Boolean false

1.3.11. areaLayer.flyToBatchedFeature(options)

定位到指定属性key值的要素对象(批量添加的面要素)

Kind : instance method of AreaLayer

Param Type Default Description
options Object

包含以下属性的对象:

options.featureKeyValue StringNumber

批量要素key值(在添加时指定)

[options.primitiveId] String

批量图元id属性值,若不设置则默认为首批添加图元的指定id的属性名称

[options.surfaceHeight] Number 0

距离椭球表面的高度

[options.offset] HeadingPitchRange

基于要素对象包围球中心的偏移

1.3.12. areaLayer.flyToBatchedArea(primitiveId, options)

定位到批量区域

Kind : instance method of AreaLayer

See

Param Type Default Description
primitiveId String

批量图元标识属性--primitiveId

options Object

定位的设置参数

[options.areaHeight] Number 0

定位平面的高度

[options.offset] HeadingPitchRange

基于要素对象包围球中心的偏移

options.callback function

定位后的回调函数

1.3.13. areaLayer.flyToArea(area, options)

定位到单独添加的面对象

Kind : instance method of AreaLayer

Param Type Default Description
area Area

单独添加的面对象

options Object

定位的设置参数

[options.areaHeight] Number 0

定位平面的高度

[options.offset] HeadingPitchRange

基于要素对象包围球中心的偏移

options.callback function

定位后的回调函数

版权所有@盈嘉互联(北京)科技有限公司 京ICP备15051988号-9 Copyright © 2022 all right reserved,powered by Gitbook该文件修订时间: 2022-07-19 11:34:25

results matching ""

    No results matching ""