ExampleBpPage 代码
import React, {Component} from 'react'
import './ExampleDrawPage.css'
import {Bp, GIS} from "iclient3d-plot-diy";
;
import {Button} from "antd";
export default class ExampleBpPage extends Component {
constructor(props) {
super(props);
this.state = {
htmlString: '<h3>正在加载中...</h3>',
bp: null,
clickBpIndex: -1,
};
}
options = [
{
"bz": true,
"bzlx": "simple",
"jbwb": "R:00017",
"type": 2002,
"code": "draw_primitive_1000_",
"useModify": false,
"lon": 102.73181802939419,
"lat": 30.982754659441543,
"height": 0
},
{
"bz": true,
"bzlx": "detail",
"jbwb": "R:00017",
"type": 2002,
"xbwb": "17/10/2019\n16:45:8\n9260.00-10400.00MHZ",
"code": "draw_primitive_1001_",
"useModify": false,
"lon": 102.74521918551825,
"lat": 30.982390144247127,
"height": 0
}
]
componentDidMount() {
fetch('./example/ExampleBpPage.md')
.then(response => response.text())
.then(mdText => {
this.setState({htmlString: window.marked.parse(mdText)});
});
//监听拨盘事件
this.mapFunction.addBpListener(function (id, dom) {
if (id && dom) {
dom.innerHTML = '';
const newElement = document.createElement('canvas');
newElement.id = 'bpCanvas';
dom.append(newElement);
const bpConfig = {
canvasId: 'bpCanvas',
items: [
{name: '图标1', img: './project3d/icon/bpImgs/icon-1.png'},
{name: '图标2', img: './project3d/icon/bpImgs/icon-2.png'},
{name: '图标3', img: './project3d/icon/bpImgs/icon-3.png'},
{name: '图标4', img: './project3d/icon/bpImgs/icon-4.png'},
]
};
this.setState({
bp: new Bp(bpConfig)
})
this.state.bp.createBp();
this.state.bp.listenClick((index) => {
this.setState({
clickBpIndex: index
});
});
}
}, this);
}
closeBp() {
this.state.bp.removeCanvasListener();
this.setState({
bp: null,
clickBpIndex: -1
})
this.mapFunction.closeBp();
}
showData() {
this.mapFunction.mapApiService.showDrawDatas(this.options);
}
render() {
return (
<div className={"example_draw_container"}>
<h3>军标绘制拨盘功能</h3>
<div className={"map_wrapper"}>
<GIS refs={
e => {
this.mapFunction = e
}
}
plotUrl={this.state.plotUrl}
mapRef={this}
showDefaultLayer={true}
/>
</div>
<Button type="primary" onClick={this.showData.bind(this)}>展示军标数据</Button>
<Button type="primary" onClick={this.closeBp.bind(this)}>关闭拨盘</Button>
{this.state.clickBpIndex > -1 && <span
style={{color: '#f00', marginLeft: '20px'}}>你点击了第 {this.state.clickBpIndex + 1} 个选项!</span>}
<div className={"code_wrapper"}>
<div dangerouslySetInnerHTML={{__html: this.state.htmlString}}></div>
</div>
</div>
)
}
}