1. LineLayer
Extends: Layer
1.1. 初始化 new LineLayer(options)
线图层,可实现线图层数据的添加、移除、缩放至和显隐等操作
Param | Type | Description |
---|---|---|
options | Object |
包含以下参数的Object对象: |
[options.name] | String |
图层名称; |
[options.show] | Boolean |
是否显示; |
[options.customGroupId] | String |
自定义分组的ID; |
Example
//通过图层管理类统一创建线图层
let lineLayer = geomap.layerManager.createLayer(BOSGeo.LayerType.LINE, 'testLine',{ customGroupId:"vector"});
1.2. 属性
属性名 | Type | Default | Description |
---|---|---|---|
show | Boolean | 是否显示图层 |
|
customMaterial | CustomLineMaterial |
BOSGeo.CustomLineMaterial.LineGrowMaterial |
lineLayer中所有非批量线要素的材质统一设置 |
1.3. 方法
1.3.1. lineLayer.add(options) ⇒ Line
添加线
Param | Type | Default | Description |
---|---|---|---|
options | Object |
包含以下参数的Object对象: |
|
options.positions | Array.<Array.<Number>> 或 Array.<Cartesian3> |
必传经纬度与高程坐标数组 [[x1,y1,z1],[x2,y2,z2]]; |
|
[options.width] | Number |
10 |
线宽 |
[options.clampToGround] | Boolean |
false |
是否贴地 (注意:贴地线需要异步加载,即等到地球先渲染完成再加载,否则会出错) |
[options.isReverse] | Boolean |
false |
是否逆向; |
[options.customMaterial] | CustomLineMaterial |
BOSGeo.CustomLineMaterial.LineColorMaterial |
线自定义材质 |
Example
//创建线图层:lineLayer
lineLayer.add({
positions: [[115.054437, 25.551279, 48], [115.07, 25.279, 48]],
width: 10,
isReverse: true,
customMaterial: BOSGeo.CustomLineMaterial.LineArrowMaterial
});
lineLayer.add({
positions: [[115.054437, 25.51279, 48], [115.07, 25.279, 48], [115.017, 25.1279, 48]],
width: 10,
isReverse: true,
customMaterial: BOSGeo.CustomLineMaterial.LineDashMaterial
});
1.3.2. lineLayer.addArcline(options) ⇒Line
添加抛物线(适用于单个数据的添加管理,不适用于批量线的一次性加载)
Param | Type | Default | Description |
---|---|---|---|
options | Object |
包含以下属性的对象: |
|
option.startPosition | Array.<Number> | Cartesian3 |
弧线起始点位置 |
|
option.endPosition | Array.<Number> | Cartesian3 |
弧线终点位置 |
|
[option.arcHeight] | Number |
50000 |
弧线最高点的高度 |
[option.arcDensity] | Number |
30 |
弧线光滑度 |
[options.width] | Number |
10 |
宽度; |
[options.clampToGround] | Boolean |
false |
是否贴地 |
[options.isReverse] | Boolean |
false |
是否逆向; |
[options.customMaterial] | CustomLineMaterial |
BOSGeo.CustomLineMaterial.LineColorMaterial |
线自定义材质 |
Example
lineLayer.addArcline({
startPosition: [115.054437, 25.551279, 48],
endPosition: [115.07, 25.279, 48],
width: 10,
isReverse: true,
customMaterial: BOSGeo.CustomLineMaterial.LineFlowMaterial
});
1.3.3. lineLayer.loadGeoJson(options) ⇒ Primitive | GroundPolylinePrimitive
通过GeoJson对象批量添加线要素对象 ( 适用于大体量geojson数据的解析 初始解析时间相较于loadInCollection会慢一些,实现方法与loadInBatch一致, 优势:加载完后性能较好,且不需要直接解析geojson数据 缺点:目前只支持颜色、线宽的个性化设置,且仅支持EPSG:4326的geojson数据 )
Param | Type | Default | Description |
---|---|---|---|
options | Object |
包含以下参数的Object对象: |
|
options.geojson | Object |
geojson对象(目前仅支持EPSG:4326坐标系,并只支持到要素和要素集合层级) |
|
options.featureKey | String |
要素标识属性名称,不指定或者指定要素值不唯一则无法进行要素定位(此时要素位置信息会保存在图元id属性中) |
|
[options.clampToGround] | Object |
false |
线要素是否贴地 |
[options.expressionTable] | Object |
{} |
表达式对照表,key是要素的属性表达式如"${Floor}>10" value是满足该表达式的自定义的结构体object, 注意:颜色表达式key的写法与Cesium.ConditionsExpression类似,详情参考: 3DTiles-Styles |
[options.defaultLineStyle] | Color |
默认线条样式,如不设置expressionTable或者expressionTable中关键属性值无法在properties中找到时采用默认样式 |
|
[options.defaultLineStyle.color] | Color |
BOSGeo.Color.RED |
线条默认颜色 |
[options.defaultLineStyle.width] | Color |
2 |
线条默认宽度 |
Example
BOSGeo.Resource.fetchJson({
url: 'http://bosgeo.boswinner.com/geoData/geojson/shenzhen_road_11893.geojson'
}).then((res) => {
const primitive = lineLayer.loadGeoJson({
geojson: res,
featureKey: 'osm_id',
expressionTable: {
"'${bz}' === '高速公路'": {
color: BOSGeo.Color.RED,
width: 6
},
"'${bz}' === '一级公路'": {
color: BOSGeo.Color.YELLOW,
width: 5
},
"'${bz}' === '二级公路'": {
color: BOSGeo.Color.ORANGE,
width: 4
},
"'${bz}' === '三级公路'": {
color: BOSGeo.Color.BLUE,
width: 3
},
"true": {
color: BOSGeo.Color.GREEN,
width: 2
}
}
});
});
1.3.4. lineLayer.loadInBatch(options) ⇒ Primitive | GroundPolylinePrimitive
同批次加载线要素对象 ( 适用于大体量非geojson或不是EPSG:4326坐标系的geojson数据的解析 初始解析时间相较于loadInCollection会慢一些,实现方法与loadGeoJson一致, 优势:加载完后性能较好,可个性化调整要素属性 缺点:目前只支持颜色、线宽的个性化设置,且需要额外的转换工作 )
Param | Type | Default | Description |
---|---|---|---|
options | Object |
包含以下参数的Object对象: |
|
options.positions | Array.<Array.<Cartesian3>> |
批量线要素顶点坐标集, (数组外层为要素,内层为要素的点坐标集) 注意:(1)单个要素中点个数必须大于2,否则要素会被跳过(2)经纬度坐标转换可参考BOSGeo.Cartesian3.fromDegreesArray和fromDegreesArrayHeights |
|
[options.propertiesList] | Array.<Object> |
[] |
批量线要素的属性集合,与positions外层对应, 注意:(1)不设置则无法进行要素个性化展示、且不便于加载后的查询(2)不建议把查询信息完全放在展示线要素中,只在里线放一下关键信息如id或个性化展示相关属性 |
options.featureKey | String |
要素标识属性名称,不指定或者指定要素值不唯一则无法进行要素定位(此时要素位置信息会保存在图元id属性中) |
|
[options.clampToGround] | Object |
false |
线要素是否贴地 |
[options.expressionTable] | Object |
{} |
表达式对照表,key是要素的属性表达式如"${Floor}>10" value是满足该表达式的自定义的结构体object, 注意:颜色表达式key的写法与Cesium.ConditionsExpression类似,详情参考: 3DTiles-Styles |
[options.defaultLineStyle] | Color |
默认线条样式,如不设置expressionTable或者expressionTable中关键属性值无法在properties中找到时采用默认样式 |
|
[options.defaultLineStyle.color] | Color |
BOSGeo.Color.RED |
线条默认颜色 |
[options.defaultLineStyle.width] | Color |
2 |
线条默认宽度 |
Example
BOSGeo.Resource.fetchJson({
url: 'http://bosgeo.boswinner.com/geoData/geojson/shenzhen_road_11893.geojson'
}).then((res) => {
const {features} = res;
const propertiesList = [];
const featurePositions = [];
var outline;
features.forEach((feature) => {
const {geometry, properties} = feature;
const {coordinates, type} = geometry;
switch (type) {
case 'LineString':
outline = [];
coordinates.forEach((point) => {
outline.push(BOSGeo.Cartesian3.fromDegrees(point[0], point[1], 1));
});
featurePositions.push(outline);
propertiesList.push(properties);
break;
case 'MultiLineString':
coordinates.forEach((polygon) => {
outline = [];
polygon.forEach((point) => {
outline.push(BOSGeo.Cartesian3.fromDegrees(point[0], point[1], 1));
});
featurePositions.push(outline);
propertiesList.push(properties);
});
break;
}
});
const primitive = lineLayer.loadInBatch({
positions: featurePositions,
propertiesList: propertiesList,
clampToGround: false,
featureKey: 'osm_id',
expressionTable: {
"'${bz}' === '高速公路'": {
color: BOSGeo.Color.RED,
width: 6
},
"'${bz}' === '一级公路'": {
color: BOSGeo.Color.YELLOW,
width: 5
},
"'${bz}' === '二级公路'": {
color: BOSGeo.Color.ORANGE,
width: 4
},
"'${bz}' === '三级公路'": {
color: BOSGeo.Color.BLUE,
width: 3
},
"true": {
color: BOSGeo.Color.GREEN,
width: 2
}
}
});
});
1.3.5. lineLayer.loadInCollection(options) ⇒ PolylineCollection
批量加载线要素对象 ( 该方法适用于小体量数据的批量加载和个性化展示, 实现方法与loadGeoJson、loadInBatch完全不同。 优势:初始加载十分快速,支持同一类型材质的个性化展示、要素级别的可视距离控制等。 缺点:要素量达到几千时可能会引起性能问题,且只支持空间线无法贴模型贴地形 )
Param | Type | Default | Description |
---|---|---|---|
options | Object |
包含以下参数的Object对象: |
|
options.positions | Array.<Array.<Array.<Cartesian3>>> |
批量线要素顶点坐标集, (数组最外层为要素,最内层为要素的点坐标集, 中间层为线轮廓及洞顶点) 注意:(1) 单个要素中点个数必须大于2,否则要素会被跳过(2)经纬度坐标转换可参考BOSGeo.Cartesian3.fromDegreesArray和fromDegreesArrayHeights |
|
[options.propertiesList] | Array.<Object> |
[] |
批量线要素的属性集合,与positions外层对应, 注意:(1)不设置则无法进行要素个性化展示、且不便于加载后的查询(2)不建议把查询信息完全放在展示线要素中,只在里线放一下关键信息如id或个性化展示相关属性 |
options.featureKey | String |
要素标识属性名称,不指定或者指定要素值不唯一则无法进行要素定位(此时要素位置信息会保存在图元id属性中) |
|
[options.expressionTable] | Object |
{} |
表达式对照表,key是要素的属性表达式如"${Floor}>10" value是满足该表达式的自定义的结构体object,内部结构与options.defaultLineStyle一致 注意:颜色表达式key的写法与Cesium.ConditionsExpression类似,详情参考: 3DTiles-Styles |
[options.defaultLineStyle] | Object |
默认线条样式,如不设置expressionTable或者expressionTable中关键属性值无法在properties中找到时采用默认样式 |
|
[options.defaultLineStyle.width] | Number |
2 |
线条默认宽度 |
[options.defaultLineStyle.maxVisibleDistance] | Number |
Number.MAX_VALUE |
线要素最远可视距离 |
[options.defaultLineStyle.customMaterial] | CustomLineMaterial |
BOSGeo.CustomLineMaterial.LineColorMaterial | 线要素自定义材质 |
Example
var expressionTable = {
"'${bz}' === '高速公路'": {
width: 6,
maxVisibleDistance: 50000,
customMaterial: new BOSGeo.CustomLineMaterial({
type: BOSGeo.CustomMaterialType.LINE_FLOW,
color: BOSGeo.Color.RED, //若要显示图片本身的颜色,需将该颜色参数设置为透明色 BOSGeo.Color.TRANSPARENT,
speedFactor: 6,
imagePath: 'https://bosgeo.boswinner.com/Assets/Images/green_line.png'
}),
},
"'${bz}' === '一级公路'": {
width: 5,
maxVisibleDistance: 25000,
customMaterial: new BOSGeo.CustomLineMaterial({
type: BOSGeo.CustomMaterialType.LINE_DASH,
color: BOSGeo.Color.YELLOW,
dashLength: 8,
dashPattern: parseInt("10011111111001", 2)
}),
},
"'${bz}' === '二级公路'": {
width: 4,
maxVisibleDistance: 18000,
customMaterial: new BOSGeo.CustomLineMaterial({
type: BOSGeo.CustomMaterialType.LINE_GROW,
color: BOSGeo.Color.ORANGE,
glowPower: 0.5,
taperPower: 0.9
}),
},
"'${bz}' === '三级公路'": {
width: 3,
maxVisibleDistance: 14000,
customMaterial: new BOSGeo.CustomLineMaterial({
type: BOSGeo.CustomMaterialType.LINE_ARROW,
color: BOSGeo.Color.BLUE,
})
},
"true": {
width: 2,
maxVisibleDistance: 10000,
customMaterial: new BOSGeo.CustomLineMaterial({
type: BOSGeo.CustomMaterialType.LINE_COLOR,
color: BOSGeo.Color.GREEN,
}),
}
}
BOSGeo.Resource.fetchJson({
url: 'http://bosgeo.boswinner.com/geoData/geojson/shenzhen_road_2514.geojson'
}).then((res) => {
const {features} = res;
const propertiesList = [];
const featurePositions = [];
var outline;
features.forEach((feature) => {
const {geometry, properties} = feature;
const {coordinates, type} = geometry;
switch (type) {
case 'LineString':
outline = [];
coordinates.forEach((point) => {
outline.push(BOSGeo.Cartesian3.fromDegrees(point[0], point[1], 1));
});
featurePositions.push(outline);
propertiesList.push(properties);
break;
case 'MultiLineString':
coordinates.forEach((polygon) => {
outline = [];
polygon.forEach((point) => {
outline.push(BOSGeo.Cartesian3.fromDegrees(point[0], point[1], 1));
});
featurePositions.push(outline);
propertiesList.push(properties);
});
break;
}
});
const primitive = lineLayer.loadInCollection({
positions: featurePositions,
propertiesList: propertiesList,
featureKey: 'osm_id',
expressionTable,
});
lineLayer.flyToBatchedLine(primitive.primitiveId)
});
1.3.6. lineLayer.flyToBatchedFeature()
定位到指定属性key值的要素对象(批量添加的线要素)
Param | Type | Default | Description |
---|---|---|---|
options.featureKeyValue | String 或 Number |
批量要素key值(在添加时指定) |
|
[options.primitiveId] | String |
批量图元id属性值,若不设置则默认为首批添加图元的指定id的属性名称 |
|
[options.surfaceHeight] | Number |
0 |
距离椭球表面的高度 |
[options.offset] | HeadingPitchRange |
基于要素对象包围球中心的偏移 |
1.3.7. lineLayer.flyToBatchedLine(primitiveId)
定位到批量线的范围
Param | Type | Description |
---|---|---|
primitiveId | String |
批量图元标识属性--primitiveId |
1.3.8. lineLayer.flyToLine(line, options)
定位到单独添加的线对象
Param | Type | Default | Description |
---|---|---|---|
line | Line |
单独添加的线对象 |
|
options | Object |
定位的设置参数 |
|
[options.lineHeight] | Number |
0 |
线所在平面的高度 |
[options.offset] | HeadingPitchRange |
基于要素对象包围球中心的偏移 |
|
options.callback | function |
定位后的回调函数 |
1.3.9. lineLayer.zoomToLayer(callback)
缩放至本图层
Param | Type | Description |
---|---|---|
callback | function |
回调函数 |
1.3.10. lineLayer.removeBatchedLine(primitiveId) ⇒ Boolean
移除批量线
Param | Type | Description |
---|---|---|
primitiveId | String |
批量图元id属性值--primitiveId |
1.3.11. lineLayer.remove(line)
根据对象移除
Param | Type |
---|---|
line | Line |
1.3.12. lineLayer.removeAll()
移除所有线图层
1.3.13. lineLayer.destroy()
销毁本图层