질문답변

제목건물삭제 레이어 On/Off시 선택되지 않은 건물이 삭제되는 오류 문의2024-12-20 17:16
카테고리GeOnDT for JS
작성자
첨부파일건물삭제 레이어 코드.txt (5.1KB)

안녕하세요.

24년 국가공간정보통합플랫폼(K-Geo)유지관리 김형준 담당입니다.

 

건물삭제 레이어 On/Off시 영역이나 단일로 선택한 건물이 삭제되지 않고 선택되지 않은 건물이 삭제되는 오류가 있어 코드 문의드립니다.

 

/*건물삭제 영역그리기 코드*/
$this.toggleClass('active')
if ($this.hasClass('active')) {
  if ($this.siblings("." + BTN_NAME_OPTION.SELECTBUILDING).hasClass('active')) {
    $this.siblings("." + BTN_NAME_OPTION.SELECTBUILDING).click();
  }
  //$parent.children("p").html($parent.children("p").html() + "[삭제중]");
  $parent.children('.closed').children('span').text($parent.children('.closed').children('span').text() + "  [삭제중]");
  gisUtil.dispToastMesg('지도에서 영역을 선택하여 지우기를 수행할 수 있습니다.', 'toastMesgDiv');

  $(".item_moreList").empty();
  $this.siblings().hide();
  $this.text("삭제종료");

  openTocMoreList($parent);

  buildingSelecter = new Union3D.select.U3dSelect();
  UnionObj.addSelect(buildingSelecter);
  buildingSelecter.active();
  buildingSelecter.setMode('area');
  var executeRemoveBuildingEnd = function (event) {
    overlayService.removeAllOverlayPopup("selectBuilding");
    if (!event.data || event.data.length == 0) {
      return;
    }
    try {
      let latlon;
      for (const data of event.data) {
        if(data._uvecBottom) {
          latlon = UnionObj.vector3ToGeoGraphic(data._uvecBottom);
          break;
        } else if (data.position.x !== 0 || data.position.y !== 0) {
          latlon = UnionObj.vector3ToGeoGraphic(data.position);
          break;
        }
      }
      if (!latlon) {
        let newPosition = {
          x : 0,
          y : 0,
          z : 0,
          isVector3: true
        };
        LoopChildren :
            for (const data of event.data) {
              for (const child of data.children) {
                if (child.position) {
                  newPosition.x = child.position.x;
                  newPosition.y = child.position.y;
                  newPosition.z = child.position.z;
                  break LoopChildren;
                }
              }
            }
        if (newPosition.x === 0 && newPosition.y === 0 && newPosition.z === 0 ) {
          console.log("position error");
        } else {
          latlon = UnionObj.vector3ToGeoGraphic(newPosition);
        }
      }
      latlon.z += 10;
      /*
      if (event.data[0]._uvecBottom) {
        latlon = UnionObj.vector3ToGeoGraphic(event.data[0]._uvecBottom);
      } else {
        latlon = UnionObj.vector3ToGeoGraphic(event.data[0].position);
      }
      latlon.z = event.data[0].position.z + 10;
      */
      let name = '건물삭제';
      let autoAnchor = 'true';
      let overlayStr = `
                            <div style="position: absolute;width: 100px;height: 40px;background-color: white;">
                            <button style="width: 48%;height: 100%; border: cornflowerblue 3px solid;" class="deleteBuilding">삭제</button>
                            <button style="width: 48%;height: 100%;border: cornflowerblue 3px solid;" class="cancelDelete">취소</button>
                            </div>
                        `;
      let overlayInfo = overlayService.makeOverlayPopup(name, latlon, overlayStr, autoAnchor, BTN_NAME_OPTION.SELECTBUILDING);
      overlayService.showOverlayPopup(overlayInfo);

      //건물삭제 이벤트
      overlayInfo.element.on('click', '.deleteBuilding', function () {
        try {
          if (!selectBuildList[contentId]) {
            selectBuildList[contentId] = {};
            selectBuildList[contentId].uIdList = [];
            selectBuildList[contentId].layerName = [];
          }
          for (var i = 0; i < event.data.length; i++) {
            if (userLayerInfoList.indexOf(event.data[i]._ulayername) > -1) {
              continue;
            }
            if (!event.data[i].visible) {
              continue;
            }
            selectBuildList[contentId].layerName.push(event.data[i]._ulayername);
            selectBuildList[contentId].uIdList.push(event.data[i].getUid());
            UnionObj.removeModel({"layer": event.data[i]._ulayername, "uid": event.data[i].getUid()});
          }
        } catch (e) {
          console.log("removeModel:" + e.message);
        }
        overlayService.removeOverlayPopup(overlayInfo);
        buildingSelecter.clear();
      });
      overlayInfo.element.on('click', '.cancelDelete', function () {
        overlayService.removeOverlayPopup(overlayInfo);
        buildingSelecter.clear();
      });
    } catch (e) {
      buildingSelecter.clear();
    }
  }
  buildingSelecter.on('end', executeRemoveBuildingEnd);
} else {
  if (buildingSelecter) {
    $parent.children('.closed').children('span').text($parent.children('.closed').children('span').text().replace("[삭제중]", ""));
    overlayService.removeAllOverlayPopup(BTN_NAME_OPTION.SELECTBUILDING);
    buildingSelecter.deactive();
    buildingSelecter.clear();
    UnionObj.removeSelect(buildingSelecter);

    $(".item_moreList").empty();
    $this.siblings().show();
    $this.text("영역선택삭제");

    openTocMoreList($parent);
  }
}

 

 

/*건물삭제 레이어 on/off시 건물 삭제되는 코드*/
else if (contentLayerType === LAYER_OPTION.LAYER_TYPE.ERASE) {
  let eraseId = $parent.attr("eraseId");
  let layerNm = $parent.siblings().attr('name');
  if (selectBuildList[eraseId] && selectBuildList[eraseId].uIdList.length !== 0) {
    if(eraseId && app.getLayerByName(layerNm) === undefined){
      selectWorkList().then (function() {
        for (let i = 0; i < selectBuildList[eraseId].uIdList.length; i++) {
          UnionObj.removeModel({
            "layer": selectBuildList[eraseId].layerName[i],
            "uid"  : selectBuildList[eraseId].uIdList[i]
          });
        }
      });
    }
    for (let i = 0; i < selectBuildList[eraseId].uIdList.length; i++) {
      UnionObj.removeModel({
        "layer": selectBuildList[eraseId].layerName[i],
        "uid"  : selectBuildList[eraseId].uIdList[i]
      });
    }
    UnionObj.updateData();
  }

}