index.jsx 40.8 KB
Newer Older
1
/* eslint-disable react/jsx-boolean-value */
2
/* eslint-disable no-unused-expressions */
3 4
/* eslint-disable no-case-declarations */
/* eslint-disable import/no-duplicates */
邓超's avatar
邓超 committed
5 6
/* eslint-disable no-new */
import React, { useEffect, useState, useRef } from 'react';
7
import { SketchPicker } from 'react-color';
8 9 10 11
import {
  ArcGISMap,
  ArcGISSceneMap,
  Drawtool,
12
  EditTool,
13 14 15
  geomUtils,
  PipenetStylesCenter,
  MapImageLayer,
16
  GraphicsLayer,
17
  watchUtils,
18
  SimpleFillSymbol,
19 20
  Graphic,
  EditAndDrawPanel,
21 22
} from '@wisdom-map/arcgismap';
import { getPipenetLayer } from '@wisdom-map/basemap';
23 24 25 26 27 28 29 30 31 32
import {
  Form,
  Input,
  Slider,
  InputNumber,
  Select,
  Button,
  Cascader,
  notification,
  Tooltip,
33 34
  Radio,
  message,
35
  Popconfirm,
36 37 38 39
  Dropdown,
  Menu,
  Space,
  Tag,
40
  Divider,
41
} from 'antd';
42 43 44 45 46 47 48 49 50
import {
  EnvironmentOutlined,
  FormOutlined,
  DoubleLeftOutlined,
  DoubleRightOutlined,
  BorderOutlined,
  CheckCircleOutlined,
  ExclamationCircleOutlined,
} from '@ant-design/icons';
邓超's avatar
邓超 committed
51 52
import classnames from 'classnames';
import { GetWebSiteConfig } from '@/services/gis/gis';
皮倩雯's avatar
皮倩雯 committed
53
import { SetServiceConfig, GetSpriteSheet } from '@/services/webConfig/api';
54
import { formatTimeStr } from 'antd/lib/statistic/utils';
皮倩雯's avatar
皮倩雯 committed
55
import styles from './index.less';
邓超's avatar
邓超 committed
56
const { Option } = Select;
57 58 59 60 61 62 63 64 65 66 67 68
const defaultMap = {
  basemaps: [
    {
      id: '高德地形',
      title: '高德地形',
      thumbnailUrl: 'assets/images/thumbnail_2.jpg',
      baseLayers: [
        {
          title: '高德地形',
          icon: '',
          layerType: 'amap-v',
          url: '',
邓超's avatar
邓超 committed
69
          opacity: 1,
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
          visible: false,
          useProxy: false,
          proxyUrl: '',
          style: '',
          extent: '',
          baseLayer: '',
          levelStart: '',
          levelEnd: '',
          levelEndEnlarge: false,
          resolution: '',
          origin: '',
          tileMatrix: '',
        },
      ],
    },
  ],
  id: '',
  title: '',
  icon: '',
  layerType: 'PipenetLayer',
  url: '',
  opacity: 1,
  showLegend: true,
  visible: true,
  useProxy: true,
  proxyUrl: '',
  extent: '',
  baseLayer: '',
  levelStart: '',
  levelEnd: null,
  resolution: '',
  origin: '',
  tileMatrix: '',
  wmtsUrl: '',
  schemename: '',
  roles: '',
  areaName: '上海市',
  boundColor: '#86c8f8',
  backgroundColor: '#000000',
  boundWidth: '10px',
  backgroundOpacity: '0.6',
111
  exportScheme: 'pandagis',
112
  customFlag: 0,
113
};
邓超's avatar
邓超 committed
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
const widgets = [
  {
    label: '缩放',
    right: 20,
    bottom: 130,
    config: {},
  },
  {
    label: '坐标',
    left: 20,
    bottom: 20,
    config: {},
  },
  {
    label: '比例尺',
    left: 60,
    bottom: 70,
    config: {},
  },
  {
    label: '复位',
    right: 20,
    bottom: 90,
    config: {},
  },
  {
    label: '图层',
    right: 20,
    bottom: 50,
    config: {},
  },
  {
    label: '底图切换',
    right: 60,
    bottom: 45,
    config: {},
  },
];
邓超's avatar
邓超 committed
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
const Map = props => {
  const { visible, onCancel, schemename } = props;
  const [form] = Form.useForm();
  const [canLoadMap, setCanLoadMap] = useState(false); // 是否加载地图
  const [colorArr, setColorArr] = useState([
    { color: '#ffffff', isCheck: false },
    { color: '#000000', isCheck: false },
    { color: '#9E9E9E', isCheck: false },
    { color: '#009688', isCheck: false },
    { color: '#2196f3', isCheck: false },
    { color: '#19233c', isCheck: false },
  ]);
  const [schemeList, setSchemeList] = useState([]);
  const [options, setOptions] = useState([]);
  const [mapsettings, setMapsettings] = useState({});
167
  const [firstList, setFirstList] = useState({});
168
  const [setttingsSave, setSetttingsSave] = useState({});
169
  const [name, setName] = useState('');
皮倩雯's avatar
皮倩雯 committed
170
  const [Schemename, setSchemename] = useState({});
171
  const [radio, setRadio] = useState();
邓超's avatar
邓超 committed
172
  const mapRef = useRef();
皮倩雯's avatar
皮倩雯 committed
173
  const styleRef = useRef();
邓超's avatar
邓超 committed
174
  const mapInfo = useRef(null);
175 176 177
  const [keep, setKeep] = useState('');
  const [keepSave, setKeepSave] = useState('');
  const [map, setMap] = useState(null);
178
  const [color, setColor] = useState('');
179
  const [colorList, setColorList] = useState('');
180
  const [keepColor, setKeepColor] = useState('');
181 182
  const [radio1, setRadio1] = useState();
  const [area, setArea] = useState('');
183 184 185 186 187 188 189 190 191 192 193
  const keep1 = useRef(null);
  const [flag, setFlag] = useState(0);
  const [toolVisible, setToolVisible] = useState(true);
  const [saveFlag, setSaveFlag] = useState(0);
  const [draw, setDraw] = useState(0); // 原方案是否已绘制了自定义行政区
  const [newDraw, setNewDraw] = useState(0);
  const [keepBorderArea, setKeepBorderArea] = useState();
  const [keepType, setKeepType] = useState('');
  const [resultData, setResultData] = useState(null);
  const [keepDraw, setKeepDraw] = useState([]);
  const [butState, setButState] = useState(false); // 绘制按钮状态
194 195
  const [load, setLoad] = useState(false);
  const [keepDataDraw, setKeepDataDraw] = useState([]);
196 197 198
  const [areaFlag, setAreaFlag] = useState(0); // 地区改变标识
  const [keepNameArea, setKeepNameArea] = useState(''); // 保存方案初始地区
  const [keepNameCustomPointExtent, setKeepNameCustomPointExtent] = useState(''); // 保存方案初始自定义区域
邓超's avatar
邓超 committed
199

邓超's avatar
邓超 committed
200 201
  useEffect(() => {
    GetWebSiteConfig({ client: 'sandbox' }).then(res => {
202
      let setttings = {};
203 204
      if (res.data.length === 0) {
        res.data.layers = [defaultMap];
205 206
        setttings = defaultMap;
      }
207 208 209 210
      setSchemeList(res.data);
      setMapsettings(res.data);
      setSetttingsSave(res.data);
      res.data.forEach(item => {
邓超's avatar
邓超 committed
211 212 213 214
        if (item.layerType === 'PipenetLayer') {
          setttings = item;
        }
      });
215 216 217 218 219 220 221 222 223 224 225 226 227
      let dalist = res.data;
      dalist.forEach(item => {
        if (item.areaName == null) {
          item.areaName = '上海市';
          item.backgroundColor = '#000000';
          item.boundColor = '#86C8F8';
          item.boundWidth = '5px';
          item.backgroundOpacity = '0.6';
        }
      });
      let list = {};
      list.layers = dalist;
      console.log(list);
皮倩雯's avatar
皮倩雯 committed
228
      debugger;
229
      setFirstList({ ...list });
邓超's avatar
邓超 committed
230 231
      setTimeout(() => {
        form.setFieldsValue({
232 233 234
          areaName: setttings.areaName ? [setttings.areaName] : ['上海市'],
          backgroundColor: setttings.backgroundColor || '#000000',
          backgroundOpacity: setttings.backgroundOpacity * 100 || '60',
235
          boundColor: setttings.boundColor || '#86C8F8',
236
          boundWidth: parseInt(setttings.boundWidth) || '5',
邓超's avatar
邓超 committed
237
          extent: setttings.extent,
238
          customPointExtent: setttings.customPointExtent,
邓超's avatar
邓超 committed
239
          schemename: setttings.schemename,
240
          exportScheme: setttings.exportScheme || 'pandagis',
241
          customFlag: setttings.customFlag,
邓超's avatar
邓超 committed
242
        });
243 244
        setKeepNameArea(setttings.areaName);

245
        setKeepBorderArea(setttings.customPointExtent);
皮倩雯's avatar
皮倩雯 committed
246
        console.log(setttings.customPointExtent);
247 248 249 250 251 252
        if (setttings.customPointExtent) {
          let aa = JSON.parse(setttings.customPointExtent);
          let data = {};
          console.log(aa);
          if (aa && aa.type) {
            setKeepDraw(aa.geometry);
253
            setKeepNameCustomPointExtent(aa.geometry);
254 255 256 257 258 259 260 261 262 263
            setKeepType(aa.type);
            data.type = aa.type;
            let rings = [];
            aa.geometry.map(i => {
              rings.push([i.x, i.y]);
            });
            let hh = {};
            hh.rings = rings;
            console.log(hh);
            data.geometry = geomUtils.toGeometry(hh);
皮倩雯's avatar
皮倩雯 committed
264
            console.log(data);
265 266 267
            setResultData({ ...data });
          }
        } else {
268
          setKeepNameCustomPointExtent(setttings.customPointExtent);
269 270 271 272 273 274 275 276 277
          setKeepDraw(setttings.customPointExtent);
        }

        if (setttings.customPointExtent) {
          setDraw(1);
        } else {
          setDraw(0);
        }
        setFlag(setttings.customFlag);
278
        setColorList(setttings.boundColor || '#86C8F8');
279
        setKeepColor(setttings.boundColor || '#86C8F8');
280
        setColor(setttings.backgroundColor || '#000000');
281 282 283 284
        setRadio(setttings.exportScheme || 'pandagis');
        if (setttings.id) {
          setKeep(setttings);
          setName(setttings.id);
皮倩雯's avatar
皮倩雯 committed
285
          setSchemename(setttings);
286 287 288
        } else {
          setName('');
        }
289

邓超's avatar
邓超 committed
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305
        setCanLoadMap(true);
      }, 0);
    });
    // 获取城市选择器列表
    window.AMap.plugin('AMap.DistrictSearch', () => {
      let districtSearch = new AMap.DistrictSearch({
        // 关键字对应的行政区级别,country表示国家
        level: 'country',
        //  显示下级行政区级数,1表示返回下一级行政区
        subdistrict: 3,
      });

      // 搜索所有省/直辖市信息
      districtSearch.search('中国', (status, result) => {
        // 查询成功时,result即为对应的行政区信息
        console.log(result, '行政区划信息');
邓超's avatar
邓超 committed
306
        result.districtList[0].districtList.push({ adcode: '100000', name: '中华人民共和国' });
邓超's avatar
邓超 committed
307 308 309 310
        setOptions(result.districtList[0].districtList);
      });
    });
  }, []);
311

312 313 314 315 316 317 318 319
  const getData = () => {
    GetWebSiteConfig({ client: 'sandbox' }).then(res => {
      let setttings = {};
      if (res.data.length === 0) {
        res.data.layers = [defaultMap];
        setttings = defaultMap;
      }
      setSchemeList(res.data);
320 321 322 323 324 325 326 327 328 329 330 331 332 333
      let dalist = res.data;
      dalist.forEach(item => {
        if (item.areaName == null) {
          item.areaName = '上海市';
          item.backgroundColor = '#000000';
          item.boundColor = '#86C8F8';
          item.boundWidth = '5px';
          item.backgroundOpacity = '0.6';
        }
      });
      let list = {};
      list.layers = dalist;
      console.log(dalist);
      // setFirstList({ ...list });
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354
      setMapsettings(res.data);
      setSetttingsSave(res.data);
      res.data.forEach(item => {
        if (item.schemename === form.getFieldsValue().schemename) {
          setttings = item;
        }
      });
      console.log(setttings);
      setTimeout(() => {
        form.setFieldsValue({
          areaName: setttings.areaName ? [setttings.areaName] : ['上海市'],
          backgroundColor: setttings.backgroundColor || '#000000',
          backgroundOpacity: setttings.backgroundOpacity * 100 || '60',
          boundColor: setttings.boundColor || '#86C8F8',
          boundWidth: parseInt(setttings.boundWidth) || '5',
          extent: setttings.extent,
          customPointExtent: setttings.customPointExtent,
          schemename: setttings.schemename,
          exportScheme: setttings.exportScheme || 'pandagis',
          customFlag: setttings.customFlag,
        });
355 356
        setKeepNameArea(setttings.areaName);

357 358 359 360 361 362 363
        setKeepBorderArea(setttings.customPointExtent);
        if (setttings.customPointExtent) {
          let aa = JSON.parse(setttings.customPointExtent);
          let data = {};
          console.log(aa);
          if (aa && aa.type) {
            setKeepDraw(aa.geometry);
364
            setKeepNameCustomPointExtent(aa.geometry);
365 366 367 368 369 370 371 372 373 374 375 376 377 378
            setKeepType(aa.type);
            data.type = aa.type;
            let rings = [];
            aa.geometry.map(i => {
              rings.push([i.x, i.y]);
            });
            let hh = {};
            hh.rings = rings;
            console.log(hh);
            data.geometry = geomUtils.toGeometry(hh);
            setResultData({ ...data });
          }
        } else {
          setKeepDraw(setttings.customPointExtent);
379
          setKeepNameCustomPointExtent(setttings.customPointExtent);
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394
        }

        if (setttings.customPointExtent) {
          setDraw(1);
        } else {
          setDraw(0);
        }
        setFlag(setttings.customFlag);
        setColorList(setttings.boundColor || '#86C8F8');
        setKeepColor(setttings.boundColor || '#86C8F8');
        setColor(setttings.backgroundColor || '#000000');
        setRadio(setttings.exportScheme || 'pandagis');
        if (setttings.id) {
          setKeep(setttings);
          setName(setttings.id);
皮倩雯's avatar
皮倩雯 committed
395
          setSchemename(setttings);
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421
        } else {
          setName('');
        }

        setCanLoadMap(true);
      }, 0);
    });
    // 获取城市选择器列表
    window.AMap.plugin('AMap.DistrictSearch', () => {
      let districtSearch = new AMap.DistrictSearch({
        // 关键字对应的行政区级别,country表示国家
        level: 'country',
        //  显示下级行政区级数,1表示返回下一级行政区
        subdistrict: 3,
      });

      // 搜索所有省/直辖市信息
      districtSearch.search('中国', (status, result) => {
        // 查询成功时,result即为对应的行政区信息
        console.log(result, '行政区划信息');
        result.districtList[0].districtList.push({ adcode: '100000', name: '中华人民共和国' });
        setOptions(result.districtList[0].districtList);
      });
    });
  };

邓超's avatar
邓超 committed
422 423
  // 获取地图实例
  const getMapInfo = viewObject => {
424 425 426 427 428 429 430 431 432 433 434 435
    console.log(areaFlag);
    // 切换方案清除自定义绘制管网;
    // const pipenetLayers = viewObject.map.layers.filter(item => {
    //   item.layerType && item.layerType == 'PipenetLayertest';
    // });
    // viewObject.map.removeMany(pipenetLayers);

    // 切换范围类型清除自定义绘制管网
    viewObject.map.layers.forEach(item => {
      if (item.layerType && item.layerType == 'PipenetLayertest') {
        viewObject.map.remove(item);
      }
436
    });
437

438
    console.log(123);
439
    setMap(viewObject);
皮倩雯's avatar
皮倩雯 committed
440 441
    console.log(viewObject);
    debugger;
442
    watchUtils.watch(viewObject, ['zoom'], newzoom => {
443
      // 鼠标滚动隐藏管网图
444 445 446 447 448 449
      viewObject.map.layers.find(layer => {
        if (layer.layerType == 'PipenetLayer') {
          layer.visible = false;
        }
      });
    });
邓超's avatar
邓超 committed
450
    mapInfo.current = viewObject;
451
    if (form.getFieldsValue().exportScheme == 'pandagis') {
452
      console.log(mapInfo.current.map.layers);
453 454 455
      let data = mapInfo.current.map.layers.find(
        item => item.layerType && item.layerType == 'PipenetLayertest',
      );
456
      console.log(data);
457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472
      if (!data) {
        // 用户自定义创建的管网图
        let aa = '';
        mapsettings.map(i => {
          if (i.schemename == form.getFieldsValue().schemename) {
            aa = i.id;
          }
        });
        const pandagis1 = new MapImageLayer({
          id: aa,
          url: `/PandaGIS/MapServer/${aa}`,
          layerType: 'PipenetLayertest',
          title: aa,
        });
        viewObject.map.add(pandagis1);
      }
473
    }
474
    setRadio1(form.getFieldsValue().customFlag);
475
    setAreaFlag(0);
邓超's avatar
邓超 committed
476
  };
477

邓超's avatar
邓超 committed
478 479 480
  // 选择颜色
  const checkColor = color => {
    form.setFieldsValue({ backgroundColor: color });
481
    setColor(color);
482
    console.log(color);
邓超's avatar
邓超 committed
483 484
    mapRef.current.updateAreaColor(color);
  };
485

邓超's avatar
邓超 committed
486 487
  // 表单修改后对地图进行配置
  const changeValue = changedFields => {
488
    console.log(changedFields);
邓超's avatar
邓超 committed
489 490 491
    if (changedFields.length === 0) {
      return;
    }
492
    let obj = JSON.parse(JSON.stringify(setttingsSave));
493
    const index = obj.findIndex(item => item.schemename === form.getFieldValue('schemename'));
邓超's avatar
邓超 committed
494 495
    switch (changedFields[0].name[0]) {
      case 'backgroundOpacity':
496 497
        obj[index].backgroundOpacity = changedFields[0].value / 100;
        mapRef.current.changeBackgroundOpacity(obj[index].backgroundOpacity);
邓超's avatar
邓超 committed
498 499
        break;
      case 'boundWidth':
500 501
        obj[index].boundWidth = changedFields[0].value;
        mapRef.current.changeBoundWidthValue(obj[index].boundWidth);
邓超's avatar
邓超 committed
502 503
        break;
      case 'areaName':
504 505 506
        obj[index].areaName = changedFields[0].value[changedFields[0].value.length - 1];
        setButState(false);
        // 如果地区与范围初始值相等则范围已绘制
507 508 509 510 511 512 513 514 515
        if (radio == 1) {
          if (keepNameArea === changedFields[0].value[changedFields[0].value.length - 1]) {
            if (keepNameArea !== '') {
              mapRef.current.changeAreaName(keepNameArea, keepDraw);
              setDraw(1);
            } else {
              setDraw(0);
              mapRef.current.changeAreaName(obj[index].areaName);
            }
516 517 518 519
          } else {
            setDraw(0);
            mapRef.current.changeAreaName(obj[index].areaName);
          }
520 521 522 523
          setAreaFlag(1);
          setFlag(0);
          Drawtool.deactivate(false);
          setArea('');
524 525 526 527
        } else {
          mapRef.current.changeAreaName(obj[index].areaName);
        }

528
        setNewDraw(0);
529
        setResultData(null);
530 531 532 533 534

        let aa = { ...firstList };
        aa.layers.map(i => {
          if (i.layerType == 'PipenetLayer') {
            i.layerType = 'dynamic';
535
            i.areaName = obj[index].areaName;
536 537 538 539 540 541 542 543 544 545
          }
          if (i.schemename == form.getFieldsValue().schemename) {
            i.backgroundColor = color;
            i.boundColor = colorList;
            i.boundWidth = form.getFieldsValue().boundWidth;
            i.backgroundOpacity = form.getFieldsValue().backgroundOpacity / 100;
            i.layerType = 'PipenetLayer';
          }
        });
        console.log(aa);
546
        // setFirstList({ ...aa });
邓超's avatar
邓超 committed
547 548
        break;
      case 'schemename':
549
        setKeepDataDraw([]);
550 551
        setRadio1('');

552 553 554 555
        GetWebSiteConfig({ client: 'sandbox' }).then(res => {
          setSchemeList(res.data);
          setMapsettings(res.data);
          setSetttingsSave(res.data);
556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577

          let dalist = res.data;
          dalist.forEach(item => {
            if (item.layerType == 'PipenetLayer') {
              item.layerType = 'dynamic';
            }
            if (item.areaName == null) {
              item.areaName = '上海市';
              item.backgroundColor = '#000000';
              item.boundColor = '#86C8F8';
              item.boundWidth = '5px';
              item.backgroundOpacity = '0.6';
              console.log(changedFields[0].value);
            }
            if (item.schemename == changedFields[0].value) {
              item.layerType = 'PipenetLayer';
            }
          });
          console.log(dalist);
          let list = {};
          list.layers = dalist;
          console.log(list);
皮倩雯's avatar
皮倩雯 committed
578
          debugger;
579
          setFirstList({ ...list });
580
        });
581
        setArea('');
邓超's avatar
邓超 committed
582
        Drawtool.deactivate(false);
583

邓超's avatar
邓超 committed
584
        let setttings;
585 586 587 588
        obj.forEach(item => {
          if (item.schemename.schemename) {
            item.schemename = item.schemename.schemename;
          }
邓超's avatar
邓超 committed
589 590 591
          if (item.schemename === changedFields[0].value) {
            item.layerType = 'PipenetLayer';
            setttings = item;
592
            console.log(item);
皮倩雯's avatar
皮倩雯 committed
593
            setSchemename(item);
594 595
            setName(item.id);
            setKeep(item);
邓超's avatar
邓超 committed
596 597 598 599
          } else {
            item.layerType = 'dynamic';
          }
        });
600

邓超's avatar
邓超 committed
601
        form.setFieldsValue({
602 603 604
          areaName: setttings.areaName ? [setttings.areaName] : ['上海市'],
          backgroundColor: setttings.backgroundColor || '#000000',
          backgroundOpacity: setttings.backgroundOpacity * 100 || '60',
605
          boundColor: setttings.boundColor || '#86C8F8',
606
          boundWidth: parseInt(setttings.boundWidth) || '5',
邓超's avatar
邓超 committed
607
          extent: setttings.extent,
608
          customPointExtent: setttings.customPointExtent,
609
          exportScheme: setttings.exportScheme || 'pandagis',
610
          customFlag: setttings.customFlag,
邓超's avatar
邓超 committed
611
        });
612 613
        setKeepNameArea(setttings.areaName);

614 615 616 617
        if (setttings.customPointExtent) {
          let aa = JSON.parse(setttings.customPointExtent);
          if (aa && aa.type) {
            setKeepDraw(aa.geometry);
618
            setKeepNameCustomPointExtent(aa.geometry);
619 620 621 622 623 624 625 626 627 628 629 630 631 632
            setKeepType(aa.type);
            let data = {};
            data.type = aa.type;
            let rings = [];
            aa.geometry.map(i => {
              rings.push([i.x, i.y]);
            });
            let hh = {};
            hh.rings = rings;
            data.geometry = geomUtils.toGeometry(hh);
            setResultData({ ...data });
          }
        } else {
          setKeepDraw(setttings.customPointExtent);
633
          setKeepNameCustomPointExtent(setttings.customPointExtent);
634 635 636 637 638 639 640 641 642 643 644
        }

        setKeepBorderArea(setttings.customPointExtent);
        setButState(false);
        setNewDraw(0);
        if (setttings.customPointExtent) {
          setDraw(1);
        } else {
          setDraw(0);
        }
        setFlag(setttings.customFlag);
645
        setColorList(setttings.boundColor || '#86C8F8');
646
        setKeepColor(setttings.boundColor || '#86C8F8');
647
        setColor(setttings.backgroundColor || '#000000');
648
        setRadio(setttings.exportScheme || 'pandagis');
649
        setRadio1(setttings.customFlag);
650

651
        mapRef.current.mapchange(obj);
邓超's avatar
邓超 committed
652 653 654 655 656 657
        break;

      default:
        break;
    }
  };
658

邓超's avatar
邓超 committed
659 660
  // 选择范围
  const onTangleClick = e => {
661
    let aa = 0;
邓超's avatar
邓超 committed
662 663 664 665
    Drawtool.activate({
      view: mapInfo.current,
      action: 'extent',
      drawEnd: data => {
666 667
        aa = 1;
        setLoad(false);
668
        setArea(data);
669
        console.log(data);
670
        const geom1 = geomUtils.toGeometry({
邓超's avatar
邓超 committed
671 672 673
          type: 'extent',
          xmin: data.rings[0][0][0],
          xmax: data.rings[0][2][0],
674 675
          ymin: data.rings[0][1][1],
          ymax: data.rings[0][0][1],
邓超's avatar
邓超 committed
676 677
        });
        form.setFieldsValue({
678 679
          extent: `${data.rings[0][0][0]},${data.rings[0][1][1]},${data.rings[0][2][0]},${
            data.rings[0][0][1]
邓超's avatar
邓超 committed
680 681
          }`,
        });
682 683 684
        mapRef.current.gotoGeometry(geom1);
      },
    });
685 686 687
    setTimeout(() => {
      console.log(aa);
    }, 0);
688 689
  };

690 691 692 693 694 695 696 697
  const saveCallBack = e => {
    setSaveFlag(1);
    console.log(e);
    if (e.geometry && e.geometry.rings) {
      let geom1 = [];
      e.geometry.rings[0].forEach(i => {
        geom1.push({ x: i[0], y: i[1] });
      });
698

699
      let area1 = form.getFieldsValue().areaName;
700
      mapRef.current.changeAreaName(area1[area1.length - 1], geom1);
701 702 703
      form.setFieldsValue({
        customPointExtent: geom1,
      });
704
      setKeepNameArea(area1[area1.length - 1]);
705
      setKeepDraw(geom1);
706
      setKeepDataDraw(geom1);
707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722
      setButState(false);
      setDraw(1);
      let data = {
        geometry: e.geometry,
        type: e.type,
      };
      setKeepType(e.type);
      setResultData({ ...data });
    } else if (e.geometry == null && draw == 0) {
      notification.error({
        message: '提示',
        duration: 3,
        description: '请先绘制范围再保存',
      });
    } else {
      setButState(false);
723 724 725
      let aa = JSON.parse(form.getFieldsValue().customPointExtent);
      form.setFieldsValue({ customPointExtent: aa.geometry });
      console.log(form.getFieldsValue().customPointExtent.geometry);
726 727
    }
    Drawtool.deactivate(false);
邓超's avatar
邓超 committed
728
  };
729

邓超's avatar
邓超 committed
730 731
  // 提交
  const onFinish = () => {
732
    if (form.getFieldsValue().customFlag == 1 && draw == 0) {
邓超's avatar
邓超 committed
733 734 735
      notification.error({
        message: '提示',
        duration: 3,
736
        description: '自定义行政区范围未绘制完成',
邓超's avatar
邓超 committed
737 738 739
      });
      return;
    }
皮倩雯's avatar
皮倩雯 committed
740 741 742 743 744 745 746 747
    if (radio == 'arcgis') {
      let style = styleRef.current.stylesCompare();
      if (JSON.stringify(style.originalStyle) == JSON.stringify(style.newStyle)) {
        console.log(123);
      } else {
        message.error('请先保存管网前端绘制方案');
        return;
      }
748
    }
749 750 751 752 753 754 755 756 757
    if (!area) {
      notification.error({
        message: '提示',
        duration: 3,
        description: '请选择复位范围再保存',
      });
      return;
    }

邓超's avatar
邓超 committed
758
    const obj = form.getFieldsValue();
759 760 761 762 763 764
    let aa = '';
    if (Array.isArray(obj.areaName)) {
      aa = obj.areaName[obj.areaName.length - 1];
    } else {
      aa = obj.areaName;
    }
765 766 767 768 769 770
    let list;
    if (obj.boundColor.hex) {
      list = obj.boundColor.hex;
    } else {
      list = obj.boundColor;
    }
771

772 773
    let data = {};
    if (obj.customPointExtent) {
774
      if (keepBorderArea && obj.customPointExtent.constructor === Array) {
775 776
        data.type = keepType;
        data.geometry = obj.customPointExtent;
777
      } else if (!keepBorderArea && obj.customPointExtent.constructor === Array) {
778 779
        data.type = keepType;
        data.geometry = obj.customPointExtent;
780
      } else {
781
        data = obj.customPointExtent;
782
        console.log(obj.customPointExtent);
783
      }
784 785 786 787 788 789 790 791 792 793 794 795 796 797
    } else if (keepDataDraw.length > 0) {
      data.type = keepType;
      data.geometry = keepDataDraw;
    } else if (keepBorderArea) {
      console.log(keepBorderArea.constructor);
      if (keepBorderArea.constructor === Array) {
        data.type = keepType;
        data.geometry = keepBorderArea;
      } else if (keepBorderArea.constructor === Object) {
        data = keepBorderArea;
      }
      console.log(keepBorderArea);
    } else {
      data = '';
798 799
    }
    console.log(data);
800 801 802
    if (JSON.stringify(data) === '{}') {
      data = null;
    }
邓超's avatar
邓超 committed
803 804
    const jsConfig = {
      extent: form.getFieldValue('extent'),
805
      customPointExtent: data,
806
      areaName: aa,
807
      boundColor: list,
邓超's avatar
邓超 committed
808 809 810
      boundWidth: `${obj.boundWidth}px`,
      backgroundColor: obj.backgroundColor,
      backgroundOpacity: obj.backgroundOpacity / 100,
811
      exportScheme: obj.exportScheme == '' ? 'pandagis' : obj.exportScheme,
812
      customFlag: obj.customFlag,
邓超's avatar
邓超 committed
813 814 815 816 817 818 819
    };
    SetServiceConfig({
      schemename: obj.schemename,
      terminalType: 'web',
      isBaseMap: false,
      jsonCfg: JSON.stringify(jsConfig),
    }).then(res => {
820 821 822 823 824
      if (res.code == '0') {
        SetServiceConfig({
          schemename: obj.schemename,
          terminalType: 'phone',
          isBaseMap: false,
825 826
          jsonCfg: JSON.stringify({
            extent: form.getFieldValue('extent'),
827
            customPointExtent: obj.customPointExtent ? data : keepBorderArea,
828
          }),
829
        }).then();
邓超's avatar
邓超 committed
830 831 832 833 834
        notification.success({
          message: '提示',
          duration: 3,
          description: '保存成功',
        });
邓超's avatar
邓超 committed
835
        let mapObj = JSON.parse(JSON.stringify(mapsettings));
836
        const index = mapObj.findIndex(
邓超's avatar
邓超 committed
837 838
          item => item.schemename === form.getFieldValue('schemename'),
        );
839 840 841 842 843
        mapObj[index].backgroundOpacity = obj.backgroundOpacity / 100;
        mapObj[index].boundWidth = `${obj.boundWidth}px`;
        mapObj[index].areaName = obj.areaName[obj.areaName.length - 1];
        mapObj[index].backgroundColor = obj.backgroundColor;
        mapObj[index].extent = form.getFieldValue('extent');
844
        mapObj[index].customPointExtent = obj.customPointExtent;
845
        mapObj[index].exportScheme = obj.exportScheme;
846
        mapObj[index].customFlag = obj.customFlag;
847 848 849 850 851
        if (obj.customPointExtent) {
          setDraw(1);
        } else {
          setDraw(0);
        }
852
        setSetttingsSave(mapObj);
邓超's avatar
邓超 committed
853
        Drawtool.deactivate(false);
854

855
        // setArea('');
856
        setKeepSave('');
857
        getData();
邓超's avatar
邓超 committed
858 859 860 861 862 863 864 865 866
      } else {
        notification.error({
          message: '提示',
          duration: 3,
          description: res.msg,
        });
      }
    });
  };
867 868 869 870 871 872 873 874 875

  const pandagis = new MapImageLayer({
    id: keep.id,
    url: `/PandaGIS/MapServer/${keep.id}`,
    layerType: 'PipenetLayertest',
    title: keep.id,
  });

  const onChange = e => {
876 877 878 879
    const { layer } = getPipenetLayer(mapInfo.current?.map);
    if (layer) {
      layer.visible = false;
    }
皮倩雯's avatar
皮倩雯 committed
880
    if (e.target.value == 'arcgis') {
881
      // 选择前端绘制时,如果界面有自定义的管网图就隐藏,打开组件自动生成前端管网图
882 883 884 885 886 887
      mapInfo.current.map.layers.forEach(item => {
        if (item.layerType && item.layerType == 'PipenetLayertest') {
          mapInfo.current.map.remove(item);
        }
      });
    } else {
888
      // 选择后端绘制时创建自定义的管网图,前端管网被组件关闭自动销毁
889 890 891 892 893
      mapInfo.current.map.add(pandagis);
    }
    setRadio(e.target.value);
  };

894
  const onChange1 = e => {
895
    setResultData(null);
896 897
    if (e.target.value == 0) {
      let data = form.getFieldsValue().areaName;
898 899
      mapRef.current.changeAreaName(data[data.length - 1]);
      setButState(false);
900
      Drawtool.deactivate();
901 902
      setRadio1(e.target.value);
    } else {
903
      console.log(keepDraw);
904 905
      if (keepDraw) {
        let area1 = form.getFieldsValue().areaName;
皮倩雯's avatar
皮倩雯 committed
906
        mapRef.current.changeAreaName(area1[area1.length - 1], keepDraw);
907 908 909 910 911 912 913 914 915 916 917 918 919 920
        let data = {};
        console.log(keepType);
        data.type = keepType;
        let rings = [];
        keepDraw.map(i => {
          rings.push([i.x, i.y]);
        });
        let hh = {};
        hh.rings = rings;
        console.log(hh);
        data.geometry = geomUtils.toGeometry(hh);
        setResultData({ ...data });
      }
      if (draw == 0) {
921
        setButState(false);
922 923
      }
      setRadio1(e.target.value);
924
    }
皮倩雯's avatar
皮倩雯 committed
925 926 927 928 929 930 931 932 933 934 935 936 937 938
    let aa = { ...firstList };
    aa.layers.map(i => {
      if (i.layerType == 'PipenetLayer') {
        i.layerType = 'dynamic';
      }
      if (i.schemename == form.getFieldsValue().schemename) {
        i.backgroundColor = color;
        i.boundColor = colorList;
        i.boundWidth = form.getFieldsValue().boundWidth;
        i.backgroundOpacity = form.getFieldsValue().backgroundOpacity / 100;
        i.layerType = 'PipenetLayer';
      }
    });
    console.log(aa);
939
    // setFirstList({ ...aa });
940 941
  };

942 943 944 945
  const onSave = e => {
    setKeepSave(e);
  };

946 947
  // 颜色选择
  const colorChange = value => {
948
    form.setFieldsValue({ boundColor: value.hex });
949
    console.log(value.hex);
950
    mapRef.current.changeBoundColor(value.hex);
951 952 953
    setColorList(value.hex);
  };

邓超's avatar
邓超 committed
954
  return (
955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971
    <div className={styles.mapContent}>
      <div
        className={classnames({
          [styles.mapTool]: true,
          [styles.mapToolHide]: !toolVisible,
        })}
      >
        {toolVisible && (
          <Form
            form={form}
            labelCol={{ span: 6 }}
            wrapperCol={{ span: 18 }}
            labelWrap
            onFieldsChange={changeValue}
            onFinish={onFinish}
          >
            <Form.Item label="切换方案" name="schemename" style={{ marginBottom: '19px' }}>
972
              <Select placeholder="请选择方案" showSearch>
973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002
                {schemeList.map((item, index) => (
                  <Option value={item.schemename} key={index}>
                    {item.schemename}
                  </Option>
                ))}
              </Select>
            </Form.Item>
            <Divider orientation="left" style={{ borderTopColor: '#99bbe8', color: '#0079c1' }}>
              <strong>范围编辑</strong>
            </Divider>
            <Form.Item label="地区选择" name="areaName" style={{ marginBottom: '19px' }}>
              <Cascader
                fieldNames={{
                  label: 'name',
                  value: 'name',
                  children: 'districtList',
                }}
                showSearch
                options={options}
                placeholder="请选择行政区"
                changeOnSelect
                allowClear={false}
              />
            </Form.Item>
            <Form.Item label="范围类型" name="customFlag" style={{ marginBottom: '19px' }}>
              <Radio.Group onChange={onChange1} value={radio1}>
                <Radio value={0}>地区选择</Radio>
                <Radio value={1}>手绘区域</Radio>
              </Radio.Group>
            </Form.Item>
1003
            {radio1 === 1 && (
1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127
              <>
                <Form.Item label="手绘区域" name="customPointExtent">
                  {butState && (
                    <Tag
                      style={{
                        width: '100px',
                        height: '27px',
                        paddingLeft: '28px',
                        paddingTop: '0px',
                        marginTop: '4px',
                        display: 'flex',
                        alignItems: 'center',
                      }}
                      color="warning"
                    >
                      绘制中
                    </Tag>
                  )}
                  {!butState && draw == 0 && (
                    <Tag
                      style={{
                        width: '100px',
                        height: '27px',
                        paddingLeft: '25px',
                        paddingTop: '0px',
                        marginTop: '4px',
                        display: 'flex',
                        alignItems: 'center',
                      }}
                      color="processing"
                      onClick={() => {
                        setButState(true);
                      }}
                    >
                      开始绘制
                    </Tag>
                  )}
                  {!butState && draw == 1 && (
                    <Tooltip title="点击按钮开始绘制">
                      <Tag
                        icon={<CheckCircleOutlined style={{ marginTop: '3px' }} />}
                        color="success"
                        style={{
                          width: '100px',
                          height: '27px',
                          paddingLeft: '21px',
                          paddingTop: '0px',
                          marginTop: '4px',
                          display: 'flex',
                          alignItems: 'center',
                        }}
                        onClick={() => {
                          setNewDraw(0);
                          setButState(true);
                        }}
                      >
                        已绘制
                      </Tag>
                    </Tooltip>
                  )}
                </Form.Item>
              </>
            )}

            <Form.Item label="遮罩颜色" name="backgroundColor" style={{ marginBottom: '19px' }}>
              <div className={styles.colorContent}>
                {colorArr.map(item => (
                  <div
                    className={classnames(styles.colorBox, {
                      [styles.currentColor]: item.color === color,
                    })}
                    key={item.color}
                    style={{ background: item.color }}
                    onClick={() => checkColor(item.color)}
                  />
                ))}
              </div>
            </Form.Item>
            <Form.Item label="透明度(%)" name="backgroundOpacity" style={{ marginBottom: '19px' }}>
              <Slider min={0} max={100} />
            </Form.Item>
            <Form.Item label="边界颜色" name="boundColor" style={{ marginBottom: '19px' }}>
              <Popconfirm
                overlayClassName={styles.Popconfirmtitle}
                placement="topLeft"
                icon={false}
                title={
                  <SketchPicker width="217px" color={colorList} onChange={e => colorChange(e)} />
                }
                okText="确认"
                cancelText="取消"
                onConfirm={() => {
                  setKeepColor(colorList);
                }}
                onCancel={() => {
                  form.setFieldsValue({ boundColor: keepColor });
                  mapRef.current.changeBoundColor(keepColor);
                  setColorList(keepColor);
                }}
              >
                <div className={styles.borderColor}>
                  <div
                    style={{
                      background: colorList,
                      width: '18px',
                      height: '10px',
                      marginLeft: '1px',
                      marginTop: '4px',
                    }}
                  />
                </div>
              </Popconfirm>
            </Form.Item>
            <Form.Item label="边界宽度" name="boundWidth" style={{ marginBottom: '19px' }}>
              <InputNumber min={1} max={10} />
            </Form.Item>
            <Divider orientation="left" style={{ borderTopColor: '#99bbe8', color: '#0079c1' }}>
              <strong>高级设置</strong>
            </Divider>
            {name ? (
              <Form.Item label="管网方案" name="exportScheme" style={{ marginBottom: '19px' }}>
                <Radio.Group onChange={onChange} value={radio}>
                  <Radio value="pandagis">整图绘制</Radio>
                  <Radio value="arcgis">实时绘制</Radio>
1128 1129
                </Radio.Group>
              </Form.Item>
1130 1131 1132 1133 1134 1135 1136 1137 1138
            ) : (
              <></>
            )}

            <Form.Item label="复位视野" style={{ marginBottom: '19px' }}>
              <div style={{ display: 'flex' }}>
                <Form.Item name="extent" style={{ marginBottom: '0', width: '100%' }}>
                  {!load && !area && (
                    <Tooltip title="点击按钮开始绘制">
1139
                      <Tag
1140 1141
                        color="processing"
                        icon={<EnvironmentOutlined style={{ marginTop: '2px' }} />}
1142 1143 1144
                        style={{
                          width: '100px',
                          height: '27px',
1145 1146
                          paddingLeft: '13px',
                          paddingTop: '0px',
1147 1148 1149 1150
                          marginTop: '4px',
                          display: 'flex',
                          alignItems: 'center',
                        }}
1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164
                        onClick={() => {
                          onTangleClick();
                          setLoad(true);
                        }}
                      >
                        开始绘制
                      </Tag>
                    </Tooltip>
                  )}

                  {load && (
                    <Tooltip title="点击按钮开始绘制">
                      <Tag
                        icon={<EnvironmentOutlined style={{ marginTop: '2px' }} />}
1165
                        color="warning"
1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177
                        style={{
                          width: '100px',
                          height: '27px',
                          paddingLeft: '20px',
                          paddingTop: '0px',
                          marginTop: '4px',
                          display: 'flex',
                          alignItems: 'center',
                        }}
                        onClick={() => {
                          onTangleClick();
                        }}
1178 1179 1180
                      >
                        绘制中
                      </Tag>
1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205
                    </Tooltip>
                  )}
                  {area && !load && (
                    <Tooltip title="点击按钮开始绘制">
                      <Tag
                        icon={<EnvironmentOutlined style={{ marginTop: '2px' }} />}
                        color="success"
                        style={{
                          width: '100px',
                          height: '27px',
                          paddingLeft: '20px',
                          paddingTop: '0px',
                          marginTop: '4px',
                          display: 'flex',
                          alignItems: 'center',
                        }}
                        onClick={() => {
                          onTangleClick();
                          setLoad(true);
                        }}
                      >
                        已绘制
                      </Tag>
                    </Tooltip>
                  )}
1206
                </Form.Item>
1207
                {/* <Tooltip title="复位视野框选">
1208 1209 1210
                    <Button
                      style={{ height: '76px', borderLeft: 'none' }}
                      icon={<EnvironmentOutlined style={{ marginTop: '5px' }} />}
1211
                      onClick={e => onTangleClick(e)}
1212
                    />
1213 1214 1215 1216 1217 1218 1219 1220 1221 1222
                  </Tooltip> */}
              </div>
            </Form.Item>
            <Form.Item wrapperCol={{ offset: 6, span: 18 }}>
              <Button type="primary" htmlType="submit">
                提交
              </Button>
            </Form.Item>
          </Form>
        )}
邓超's avatar
邓超 committed
1223

1224 1225 1226 1227 1228
        <div className={styles.switcher}>
          {toolVisible && (
            <Tooltip title="隐藏配置栏">
              <DoubleLeftOutlined onClick={() => setToolVisible(false)} />
            </Tooltip>
邓超's avatar
邓超 committed
1229
          )}
1230 1231 1232 1233
          {!toolVisible && (
            <Tooltip title="显示配置栏">
              <DoubleRightOutlined onClick={() => setToolVisible(true)} />
            </Tooltip>
1234
          )}
邓超's avatar
邓超 committed
1235 1236
        </div>
      </div>
1237 1238 1239 1240
      <div className={styles.mapBox}>
        {canLoadMap && (
          <ArcGISSceneMap
            ref={mapRef}
1241
            filterMap={true}
1242 1243
            getMapInfo={e => getMapInfo(e)}
            widgets={widgets}
1244
            config={firstList}
1245 1246 1247 1248 1249
            client="sandbox"
          />
        )}
        {radio == 'arcgis' ? (
          <PipenetStylesCenter
皮倩雯's avatar
皮倩雯 committed
1250
            schemeName={Schemename.schemename}
1251 1252 1253
            mapServerName={name}
            view={map}
            savaCallback={onSave}
皮倩雯's avatar
皮倩雯 committed
1254
            ref={styleRef}
皮倩雯's avatar
皮倩雯 committed
1255
            pipenetLayer={Schemename}
1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266
          />
        ) : (
          <></>
        )}
        {radio1 == 1 && butState ? (
          <>
            <span>{console.log(form.getFieldsValue().areaName)}</span>
            <EditAndDrawPanel
              view={mapInfo.current}
              editType={['POLYGON', 'EXTENT', 'CIRCLE']}
              defaultGraphic={resultData}
1267 1268 1269 1270
              areaName={
                form.getFieldsValue().areaName &&
                form.getFieldsValue().areaName[form.getFieldsValue().areaName.length - 1]
              }
1271 1272 1273 1274 1275 1276 1277 1278 1279 1280
              useActivePanel
              colorConfigBtnShow
              handleBtnShow
              callback={saveCallBack}
            />
          </>
        ) : (
          <></>
        )}
      </div>
邓超's avatar
邓超 committed
1281 1282 1283 1284 1285
    </div>
  );
};

export default Map;