1. Html2CanvasLayer
Extends: Layer
1.1. 初始化 new Html2CanvasLayer(options)
标签(自定义广告牌)。创建一个图层,实现html元素转换为canvas,并通过billboard加载到三维场景中
Param | Type | Default | Description |
---|---|---|---|
options | Object |
配置选项 |
|
[options.isOpenSimplify] | Boolean |
true |
是否开启广告牌抽稀功能,避免叠加遮挡,默认true开启 |
Example
let geomap = new BOSGeo.GeoMap('bosgeoContainer'); //初始化
let htm2can = layerManager.createLayer(BOSGeo.LayerType.HTML2CANVAS, 'html2canvas图层');
1.2. 方法
1.2.1. html2CanvasLayer.add(options) ⇒ Promise
将html元素通过转换添加至指定坐标位置
Returns : Promise
-
包含billboard的Promise对象
Param | Type | Default | Description |
---|---|---|---|
options | Object |
配置选项 |
|
[options.id] | String |
标签标识id, |
|
[options.position] | Array.<Number> |
必填,经纬度的坐标位置 |
|
[options.html] | String |
必填,自定义的html内容,文字内容不能写在html字符串内,需要在textNodeClassAndContentArr参数传入, html中标签的class(类名)对应的样式需要自定义 |
|
[options.textNodeClassAndContentArr] | Number |
[] |
广告牌的含有文字的标签的类名和文字内容数组:className是该标签的类名需在html字符串中唯一(类名对应的标签是需要添加content文字的标签),content是文字,如{className: "bosgeo-icon1_name_content",content: "图标标签"},如果内容需要换行(div内的内容使用 ' |
[options.offset] | Array.<Number> |
[0, 0] |
标签的位置偏移像素值 |
[options.scale] | Number |
1 |
缩放比例 |
[options.farScale] | Number |
0.0 |
相机拉远,地球缩小时,标签缩放的比例 |
[options.horizontalOrigin] | String |
'CENTER' |
水平方向对齐方式,可选项有'CENTER'(中心对齐)、'LEFT'(左对齐)、'RIGHT'(右对齐) |
[options.verticalOrigin] | String |
'CENTER' |
垂直方向对齐方式,可选项有'CENTER'(中心对齐)、'BOTTOM'(底边对齐)、'BASELINE'(若包含文字,则文字底边对齐;否则同BOTTOM)、'TOP'(顶边对齐) |
[options.attribute] | Object |
null | 自定义的一些属性,默认为null |
Example
//Example 1.插件内容(content)不需要换行的标签
let htm2can = layerManager.createLayer(BOSGeo.LayerType.HTML2CANVAS, 'html2canvas图层');
htm2can.add({
id: 'test',
position: [114, 23 + 0.001, 1.1],
html: `<div class="bosgeo-titleBack1">
<div class="bosgeo-title_name bosgeo-title_name1"></div>
<div class="bosgeo-title_content bosgeo-title_content1" ></div>
</div> `,
textNodeClassAndContentArr: [
{
className: "bosgeo-title_name bosgeo-title_name1",// 表示需要在类名 "bosgeo-title_name bosgeo-title_name1" 的标签上添加 "标题标签1"
content: "标题标签1"
},
{
className: "bosgeo-title_content bosgeo-title_content1",// 表示需要在类名 "bosgeo-title_content bosgeo-title_content1" 的标签上添加 "标题标签内容1"
content: "标题标签内容1"
}
]
})
//Example 2.插件内容(content)需要换行的标签
let htm2can = layerManager.createLayer(BOSGeo.LayerType.HTML2CANVAS, 'html2canvas图层');
htm2can.add({
id: 'test',
position: [114, 23 + 0.001, 1.1],
html: `<div class="bosgeo-titleBack1">
<div class="bosgeo-title_name bosgeo-title_name1"></div>
<div class="bosgeo-title_content bosgeo-title_content1" ></div>
</div> `,
textNodeClassAndContentArr: [
{
className: "bosgeo-title_name bosgeo-title_name1",// 表示需要在类名 "bosgeo-title_name bosgeo-title_name1" 的标签上添加 "标题标签1"
content: "标题标签1"
},
{
className: "bosgeo-title_content bosgeo-title_content1",// 表示需要在类名 "bosgeo-title_content bosgeo-title_content1" 的标签上添加 "标题标签内容1"
content: "标题标签内容1 <br/> 内容第二行 <br/>内容第三行"
}
]
})
1.2.2. html2CanvasLayer.addList()
将html元素通过转换添加至指定坐标位置
Returns : Promise
-
包含billboardList数组的Promise对象
Param | Type | Description |
---|---|---|
optionsArr | Array |
多个options配置选项 |
Example
let htm2can = layerManager.createLayer(BOSGeo.LayerType.HTML2CANVAS, 'html2canvas图层');
let optionsArr = [];
for (let i = 1; i <= 100; i++) {
let position = [114 + 0.0001 * (i + 2), 23.003 + 0.0001 * (i + 2), 0.1];
let textNodeClassAndContentArr = [
{
className: "pointText pointText1",
content: "普通标签" + (i + 1)
}
];
let options = {
id: "test" + i,
position,
html: `<div class="pointBackg1">
<div class="pointText pointText1"></div>
</div>`,
width: 164,
height: 137,
textNodeClassAndContentArr,
// scale: 1 + 0.1 * i
};
optionsArr.push(options);
}
htm2can.addList(optionsArr).then(billboardList => {
htm2can.zoomToLayer();
});
1.2.3. html2CanvasLayer.openSimplifyBillboard(fireType, [level])
开启抽稀, 一种是根据camera变化进行检测抽稀,另一种是根据鼠标滚轮滚动进行检测抽稀
Param | Type | Default | Description |
---|---|---|---|
fireType | String |
触发检测的类型,包含'cameraChange','wheelChange' |
|
[level] | Number |
3 |
抽稀的级别,数值越小,抽稀程度越大,范围[1-10] |
Example
htm2can.openSimplifyBillboard('cameraChange');
1.2.4. html2CanvasLayer.closeSimplifyBillboard([fireType])
关闭抽稀
Param | Type | Default | Description |
---|---|---|---|
[fireType] | String |
触发类型,用户不用输入,内部切换监听调用时自动指定htm2can.closeSimplifyBillboard(); |
1.2.5. html2CanvasLayer.show(bool)
显隐
Param | Type | Default | Description |
---|---|---|---|
bool | Boolean |
true为显示,false为隐藏 |
Example
htm2can.show(true);
1.2.6. html2CanvasLayer.zoomToLayer(callback)
缩放至本图层
Param | Type | Description |
---|---|---|
callback | function |
回调函数 |
Example
htm2can.zoomToLayer();
1.2.7. html2CanvasLayer.getBillboardById(id) ⇒ Billboard
根据id获取标签元素
Param | Type | Description |
---|---|---|
id | String |
标签id |
Example
let bb = htm2can.getBillboardById(id);
1.2.8. html2CanvasLayer.setVisible(billboard, visible)
设置单个标签显隐
Param | Type | Description |
---|---|---|
billboard | Billboard |
使用getBillboardById方法获得的billboard标签对象 |
visible | Boolean |
true为显示,false为隐藏 |
Example
let bb = htm2can.getBillboardById(id);
htm2can.setVisible(bb, true)
1.2.9. html2CanvasLayer.zoomTo(billboard)
缩放至billboard点标签对象
Param | Type | Description |
---|---|---|
billboard | Billboard |
使用getBillboardById方法获得的billboard标签对象 |
Example
let bb = htm2can.getBillboardById(id);
htm2can.zoomTo(bb)
1.2.10. html2CanvasLayer.updatePosition(billboard, position)
更新billboard的位置坐标
Param | Type | Description |
---|---|---|
billboard | Billboard |
使用getBillboardById方法获得的billboard标签对象 |
position | Array.<Number> |
经纬度和高程组成的数组 |
Example
let bb = htm2can.getBillboardById(id);
htm2can.updatePosition(bb, [112, 24, 30])
1.2.11. html2CanvasLayer.removeById(id)
根据id删除指定元素
Param | Type | Description |
---|---|---|
id | String |
标签id |
Example
htm2can.removeById(id)
1.2.12. html2CanvasLayer.removeAll()
删除所有添加的元素
1.2.13. html2CanvasLayer.destroy()
销毁本图层
1.2.14. html2CanvasLayer.openClickZoomTo()
开启点击某个标签缩放至该点标签事件
1.2.15. html2CanvasLayer.closeClickZoomTo()
关闭点击某个标签缩放至该点标签事件
1.2.16. html2CanvasLayer.openMoveInPointer()
开启鼠标移入点标签变为pointer手形事件
1.2.17. html2CanvasLayer.closeMoveInPointer()
关闭鼠标移入点标签变为pointer手形事件