• Arcgisapi for js 在地图上通过鼠标实时画面


     draw() {
          this.view.container
            .querySelector(".esri-view-root > .esri-view-surface")
            .setAttribute("data-cursor", "crosshair");//设置鼠标的样式变为十字架
          let graphicslayer = new this.esriMudules.GraphicsLayer();//创建一个图形图层来存储画出来的图层。也可以直接将画出来的图层加载到view中,不用图层(使用下面注释掉的代码)
          this.map.add(graphicslayer);
          let activeGraphic = null;//存储当前正在画的图形
          let draw = this.esriMudules.Draw({ view: this.view });//创建画图对象
          let drawAction = draw.create("polygon", { mode: "click" });//定义画的几何类型和画图方式
          drawAction.on(//定义画图触发的事件
            [
              "vertex-add", //单击鼠标添加点
              "vertex-remove",
              "cursor-update", //鼠标移动的事件
              "redo",
              "undo",
              "draw-complete",//双击鼠标完成画图时触发事件
            ],
            (evt) => {
              //console.log(evt.type);
      //当鼠标移动和点击添加点的时候,判断画的点等于两个时显示线,大于两个时显示面
              if (evt.type == "vertex-add" || evt.type == "cursor-update") {
                if (evt.vertices.length < 2) {
                  return;
                } else if (evt.vertices.length == 2) {
                  if (activeGraphic) {//需要先移除之前画的然后在加入现在画的
                    //this.view.graphics.remove(activeGraphic);
                    graphicslayer.graphics.remove(activeGraphic);
                  }
                  let polyline = this.esriMudules.Polyline({
                    paths: [evt.vertices],
                    spatialReference: this.view.spatialReference,
                  });
                  activeGraphic = new this.esriMudules.Graphic({
                    geometry: polyline,
                    symbol: {
                      type: "simple-line",
                      color: [78, 201, 162],
                       "2px",
                      style: "solid",
                    },
                  });
                  //this.view.graphics.add(activeGraphic);
                  graphicslayer.graphics.add(activeGraphic);
                } else {
                  if (activeGraphic) {
                    //this.view.graphics.remove(activeGraphic);
                    graphicslayer.graphics.remove(activeGraphic);
                  }
                  let ring = [...evt.vertices, evt.vertices[0]];//闭合环
                  let polygonGeometry = new this.esriMudules.Polygon({
                    rings: [ring],
                    spatialReference: this.view.spatialReference,
                  });

                  // 将逆时针转到顺时针,是为了解决arcgisapi for js逆时针不填充的问题
                  if (!polygonGeometry.isClockwise(ring)) {
                    for (
                      let from = 1, to = ring.length - 2;
                      from < to;
                      ++from, --to
                    ) {
                      let c = ring[from];
                      ring[from] = ring[to];
                      ring[to] = c;
                    }
                    polygonGeometry = new this.esriMudules.Polygon({
                      rings: [ring],
                      spatialReference: this.view.spatialReference,
                    });
                  }

                  // 避免自交
                  if (polygonGeometry.isSelfIntersecting) {
                    graphicslayer.graphics.add(activeGraphic);
                    return;
                  }

                  activeGraphic = new this.esriMudules.Graphic({
                    geometry: polygonGeometry,
                    symbol: {
                      type: "simple-fill",
                      color: [78, 201, 162, 0.3],
                      style: "solid",
                      outline: {
                        color: [255, 255, 255, 0.5],
                         "2px",
                      },
                    },
                  });
                  //this.view.graphics.add(activeGraphic);
                  graphicslayer.graphics.add(activeGraphic);
                }

                graphicslayer.add(this.activeGraphic);
              }
              if (evt.type == "draw-complete") {//完成画图后获取画的图层,并将鼠标变回为箭头
                console.log(evt.vertices);
                this.view.container
                  .querySelector(".esri-view-root > .esri-view-surface")
                  .setAttribute("data-cursor", "default");
              }
            }
          );
        },
  • 相关阅读:
    简单事务使用
    sql in(1,2,3)参数化查询,错误在将 varchar 值 '1,2,3,4' 转换成数据类型 int 时失败
    处理金额小数点后的零
    json时间格式化问题
    读取接口XML和批量导入数据SqlBulkCopy
    list操作 foreach和for的区别
    10.16 一起去修仙 !mv
    10.9 自动生成计算题输入答案判断正误;计算BMI
    9.25九道题
    9.18作业 杨月(1636050091)练习题
  • 原文地址:https://www.cnblogs.com/maycpou/p/14814300.html
Copyright © 2020-2023  润新知