ExampleDrawPage 代码
import React, {Component} from 'react'
import './ExampleDrawPage.css'
import {GIS} from "../iclient3d-plot-diy";
;
import {Button} from "antd";
export default class ExampleDrawPage extends Component {
optionObjs = {
"目标简标": {
bz: true,
bzlx: 'simple',
jbwb: 'R:00017',
type: "2002",
returnHeight: true,
useModify: false,
lon: 102.73054539488224, lat: 31.005468100060593, height: 0,
points: [],
iconSize: [[20, 20], [30, 30], [40, 40]]
},
"目标详标": {
bz: true,
bzlx: 'detail',
jbwb: 'R:00017',
xbwb: "17/10/2019\n16:45:8\n9260.00-10400.00MHZ",
type: "2002",
useModify: false,
lon: 102.70054539488224, lat: 31.000468100060593, height: 0,
points: [],
iconSize: [[20, 20], [30, 30], [40, 40]]
},
"飞行简标": {
bz: true,
bzlx: 'simple',
jbwb: "P:00019",
type: "fx",
useModify: false,
lon: 102.76054539488224, lat: 31.000468100060593, height: 0,
points: [{lon: 102.76554539488224, lat: 31.000468100060593, height: 0}, {
lon: 102.76904539488224,
lat: 30.992468100060593,
height: 0
}],
iconSize: [[20, 20], [30, 30], [40, 40]]
},
"飞行详标": {
bz: true,
bzlx: 'detail',
jbwb: 'P:00019',
xbwb: "F16-1\n美国\n16:45:56\nR:00019\nC:00019",
type: "fx",
useModify: false,
lon: 102.73054539488224, lat: 31.001068100060593, height: 0,
points: [{lon: 102.73554539488224, lat: 31.001068100060593, height: 0}, {
lon: 102.73904539488224,
lat: 30.992468100060593,
height: 0
}],
iconSize: [[20, 20], [30, 30], [40, 40]]
},
"雷达对抗侦察区域": {
type: "lddkzcqy",
bj: 1,
qsjd: 30,
zzjd: 75,
lon: 102.72004539488224, lat: 31.001068100060593, height: 0,
useModify: false,
iconSize: [[20, 20], [30, 30], [40, 40]]
},
"雷达对抗干扰波束": {
type: 'lddkgrps',
bj: 1,
qsjd: 30,
zzjd: 75,
lon: 102.72004539488224, lat: 30.991068100060593, height: 0,
useModify: false,
iconSize: [[20, 20], [30, 30], [40, 40]]
},
"雷达对抗测向线": {
type: "lddkcxx",
kcwb: "10110",
kcgls: 1,
kcjd: 30,
useModify: false,
lon: 102.76054539488224, lat: 31.011068100060593, height: 0,
points: []
},
"雷达对抗关系": {
type: "lddkgx",
kcwb: "10110",
kcgls: 1,
kcjd: 30,
useModify: false,
lon: 102.78054539488224,
lat: 31.015068100060593,
height: 0,
points: []
},
"雷达对目标探测": {
type: "lddmbtc",
bj: 0.5,
qsjd: 0,
zzjd: 360,
lon: 102.71004539488224, lat: 30.990068100060593, height: 0,
useModify: false,
},
"通信对抗侦察区域": {
type: "txdkzcqy",
bj: 0.5,
qsjd: 0,
zzjd: 360,
lon: 102.69804539488224, lat: 30.990068100060593, height: 0,
useModify: false,
},
"通信对抗干扰波束": {
type: "txdkgrps",
bj: 1,
qsjd: 30,
zzjd: 75,
lon: 102.76004539488224, lat: 30.991068100060593, height: 0,
useModify: false,
},
"通信对抗测向线": {
type: "txdkcxx",
kcgls: 1,
kcjd: 30,
kcwb: "10110",
useModify: false,
lon: 102.76854539488224, lat: 31.009068100060593, height: 0,
points: []
},
"通信畅通区域": {
type: 'txctqy',
bj: 0.5,
qsjd: 0,
zzjd: 360,
lon: 102.71504539488224, lat: 30.980068100060593, height: 0,
useModify: false,
},
"通信网标绘": {
type: "txw",
useModify: false,
lon: 102.70854539488224, lat: 31.0098468100060593, height: 0,
points: []
},
"光电对抗侦察区域": {
type: 'gddkzcqy',
bj: 0.5,
qsjd: 0,
zzjd: 360,
lon: 102.69054539488224, lat: 31.0098468100060593, height: 0,
useModify: false,
},
"光电有源对抗干扰波束": {
type: 'gdyydkgrbs',
kcgls: 1,
kcjd: 30,
lon: 102.67054539488224, lat: 31.0098468100060593, height: 0,
useModify: false,
},
"漫反射干扰区域": {
type: 'mfsgrqy',
bj: 1,
qsjd: 30,
zzjd: 75,
lon: 102.67054539488224, lat: 31.0028468100060593, height: 0,
useModify: false,
},
'烟幕形成区域': {
type: 'ymxcqy',
points: [{lon: 102.64984, lat: 30.99237, height: 0},
{lon: 102.66012682459443, lat: 30.995109020954718, height: 0},
{lon: 102.67126799815856, lat: 30.98766239848537, height: 0},
{lon: 102.64984, lat: 30.983747593478107, height: 0},
{lon: 102.64984, lat: 30.99237, height: 0}],
useModify: false,
},
"掩护区域": {
type: 'yhqy',
points: [{lon: 102.642853926199, lat: 31.012509646376447, height: 0},
{lon: 102.65927322610115, lat: 31.01540811637356, height: 0},
{lon: 102.66192135373299, lat: 31.005988487769518, height: 0},
{lon: 102.64755620178961, lat: 31.00246196283815, height: 0},
{lon: 102.642853926199, lat: 31.012509646376447, height: 0}],
useModify: false,
},
"协同关系": {
type: 'xtgx',
points: [{lon: 102.642853926199, lat: 31.012509646376447, height: 0},
{lon: 102.66192135373299, lat: 31.005988487769518, height: 0}],
useModify: false,
},
"干扰线": {
type: 'grx',
points: [{lon: 102.732420985008, lat: 30.97556325857848, height: 0},
{lon: 102.73983041603873, lat: 30.97504986175468, height: 0}],
useModify: false
},
"预警线": {
type: 'yjx',
useModify: false,
points: [{lon: 102.732420985008, lat: 30.97956325857848, height: 0},
{lon: 102.73983041603873, lat: 30.98004986175468, height: 0}]
},
"目标分配线": {
type: 'mbfpx',
useModify: false,
points: [{lon: 102.732420985008, lat: 30.97756325857848, height: 0},
{lon: 102.73983041603873, lat: 30.97804986175468, height: 0}]
},
"目标醒目": {
bz: true,
xz: true,
bzlx: 'simple',
jbwb: 'R:00017',
type: "2002",
returnHeight: true,
useModify: false,
lon: 102.73554539488224, lat: 31.005068100060593, height: 0,
points: []
},
}
drawOps = [];
timer = null;
constructor(props) {
super(props);
this.state = {
htmlString: '<h3>正在加载中...</h3>',
};
}
componentDidMount() {
fetch('./example/ExampleDrawPage.md')
.then(response => response.text())
.then(mdText => {
this.setState({htmlString: window.marked.parse(mdText)});
});
}
showOptions = () => {
if (this.mapFunction) {
let options = [];
for (let key in this.optionObjs) {
options.push(this.optionObjs[key]);
}
this.mapFunction.mapApiService.showDrawDatas(options);
}
};
async draw(option) {
this.closeUpdate();
option.useModify = true;
delete option.points;
delete option.lon;
delete option.lat;
delete option.height;
let p = await this.mapFunction.mapApiService.draw(option)
this.drawOps.push(p);
}
export() {
let op = [];
let draws = this.mapFunction.mapApiService.getAllDraw();
for (let d of draws) {
let dd = this.mapFunction.mapApiService.exportDraw(d.code);
if (dd) {
op.push(dd);
}
}
console.log(op);
alert(JSON.stringify(op));
}
doUpdate() {
if (this.timer) {
clearInterval(this.timer);
this.timer = null;
}
let i = 0;
this.timer = setInterval(() => {
i = i + 1;
this.updateOption(i);
}, 1000);
}
closeUpdate() {
if (this.timer) {
clearInterval(this.timer);
this.timer = null;
}
}
updateOption(i) {
for (let d of this.drawOps) {
let dd = d.export();
let op = {};
if (dd.jbwb) {
op.jbwb = '更新' + i;
}
if (dd.bj) {
op.bj = dd.bj + 0.01;
}
if (dd.kcwb) {
op.kcwb = '更新' + i;
}
if (dd.lon && dd.lat) {
dd.lon = dd.lon + 0.001;
dd.lat = dd.lat + 0.0001;
op.lon = dd.lon;
op.lat = dd.lat;
}
if (dd.points) {
op.points = dd.points;
for (let point of op.points) {
point.lon = point.lon + 0.001;
point.lat = point.lat + 0.0001;
}
}
this.mapFunction.mapApiService.updateDraw(d.code, op);
}
}
drawTest() {
let op = {
"bz": true,
"bzlx": "simple",
"jbwb": "R:00017",
"type": "2002",
text: "测试文本",
"code": "draw_primitive_1000_",
"lon": 102.7381995451764,
"lat": 30.984122686676084,
"height": 0
};
this.mapFunction.mapApiService.showDrawDatas([op]);
}
changSize() {
if (this.timer) {
clearInterval(this.timer);
this.timer = null;
}
let i = 10;
let draws = this.mapFunction.mapApiService.drawPlotObjs;
this.timer = setInterval(() => {
i = i + 1;
for (let key in draws) {
let d = draws[key];
this.mapFunction.mapApiService.dyPlotService.changSize(d, i, i);
}
}, 1000);
}
changColor() {
this.mapFunction.mapApiService.dyPlotService.changeLineColor("#00FFE5");
}
setDrawScaleOptions() {
let options = [
{
scales: [0, 50],
width: 20,
height: 20
},
{
scales: [50, 500],
width: 32,
height: 32
},
{
scales: [500, 10000],
width: 64,
height: 64
}
]
this.mapFunction.mapApiService.setDrawScaleOptions(options);
alert('设置成功!')
}
render() {
let buttons = [];
let obs = JSON.parse(JSON.stringify(this.optionObjs));
for (let key in obs) {
let option = obs[key];
buttons.push(<Button type="primary" onClick={this.draw.bind(this, option)} key={key}>{key}</Button>);
}
return (
<div className={"example_draw_container"}>
<h3>军标绘制/展示已有的军标数据</h3>
<div className={"map_wrapper"}>
<GIS refs={
e => {
this.mapFunction = e
}
}
iconScales={[[0, 2000], [2000, 10000], [10000, 5000000]]}
plotUrl={this.state.plotUrl}
mapRef={this}
showDefaultLayer={true}
/>
</div>
<Button type="primary" onClick={this.showOptions.bind(this)}>显示已有标绘数据</Button>
{buttons}
<Button type="primary" onClick={this.export.bind(this)}>导出绘制配置</Button>
{/*<Button type="primary" onClick={this.doUpdate.bind (this)}>更新</Button>*/}
{/*<Button type="primary" onClick={this.closeUpdate.bind (this)}>退出更新</Button>*/}
{/*<Button type="primary" onClick={this.drawTest.bind (this)}>测试</Button>*/}
{/*<Button type="primary" onClick={this.changSize.bind (this)}>测试改变选中军标大小</Button>*/}
{/*<Button type="primary" onClick={this.changColor.bind (this)}>测试改变选中军标颜色</Button>*/}
{/*<Button type="primary" onClick={this.setDrawScaleOptions.bind (this)}>测试设置军标的比例尺</Button>*/}
<div className={"code_wrapper"}>
<div dangerouslySetInnerHTML={{__html: this.state.htmlString}}></div>
</div>
</div>
)
}
}