geoserver+postgis+openlayers实现数据的更改

效果图如下

点击地图出现位置标记并且出现输入框可输入点位名称
显示点位名称以及动态设置样式

先设置点位要使用的样式,代码如下

createStyle(name) {
      return new Style({
        image: new Icon({
          scale: 0.1,
          anchor: [0.5, 1],
          src: this.src
        }),
        text: new Text({
          text: name,
          textAlign: "center",
          offsetY: -30,
          fill: new Fill({
            color: "yellow"
          }),
          backgroundFill: new Fill({
            color: "#750075"
          })
        })
      });
    }

样式的设置采用了函数的方式,根据传入的name来确定地图上面显示的文字。

加载画图工具,在画图结束后加载输入框设置点位name信息

addInteraction(geomType) {
      this.draw = new Draw({
        source: this.pointSource,
        type: geomType,
        stopClick: true
      });
      this.snap = new Snap({
        source: this.pointSource
      });
      this.draw.on("drawend", evt => {
        if (evt.feature != null) {
          this.isCanUse = true;
          this.map.removeInteraction(this.draw);
          this.overlay.setPosition(evt.feature.getGeometry().getCoordinates());
          this.map.addOverlay(this.overlay);
          let geometryCoordinates = evt.feature.getGeometry().getCoordinates();
          this.feature = new Feature({
            geom: new Point([geometryCoordinates[1], geometryCoordinates[0]])
          });
        }
      });
    }

点击确定后输入框中有文字时将该文字设置为新增feature的name属性,并且触发新增函数,将新增的feature写入数据库中并且刷新界面显示最新的地图

确定按钮事件

onSubmit() {
      if (!this.formInline.name) {
        this.$message.error("请输入道观名称");
        return;
      }
      this.feature.setGeometryName("geom");
      this.feature.set("name", this.formInline.name);
      // this.feature.setStyle(this.createStyle(this.feature.values_.name));
      this.transact("insert", this.feature, "postgisdaoguan");

      this.isCanUse = false;
      this.overlay.setPosition(null);
      this.addClick();
    }

新增feature写入数据库事件

transact(transType, feat, layerName) {
      if (layerName == "") {
        return;
      }
      var node;
      var s;
      var formatWFS = new WFS();
      switch (transType) {
        case "insert":
          node = formatWFS.writeTransaction([feat], null, null, {//第二个参数是修改,第三个是删除
            featureType: layerName,
            featurePrefix: "dao",
            featureNS: "http://localhost/dao", // 注意这个值必须为创建工作区时的命名空间URI
            srsName: "EPSG:4326"
          });
          break;
        case "update":
          node = formatWFS.writeTransaction(null, [feat], null, {
            featureType: layerName,
            featureNS: "http://localhost/dao", // 注意这个值必须为创建工作区时的命名空间URI
            srsName: "EPSG:4326"
          });
          break;
      }
      s = new XMLSerializer();
      var str = s.serializeToString(node);
      axios({
        method: "post",
        url: "http://localhost:8519/geoserver/dao/wfs",
        data: str,
        headers: {
          "Content-type": "text/xml"
        }
      }).then(res => {
        this.pointSource.clear();
        this.wfsSource = new vectorSource({
          url:
            "http://localhost:8519/geoserver/dao/wfs?" +
            "service=WFS&version=1.1.0&" +
            "request=GetFeature&typeName=dao:postgisdaoguan&" +
            "outputFormat=json&srsname=EPSG:4326",
          format: new GeoJSON({
            geometryName: "geom"
          })
        });
        this.wfsLayer.setSource(this.wfsSource);
      });
    }

在使用代码的时候url都要改成自己发布的服务。
在开发这个功能的时候我采用的是vue+element-ui+openlayers+geoserver+postgis结合开发,大家在使用我写的这部分代码的时候请自己根据情况适当进行改造,并且我这里只写了增加的功能,删除与修改请大家自行改造。1
实现该功能的vue组件
提取码:0euh


  1. writeTransaction中的参数,要素写在第一个参数表示新增,第二个表示修改,第三个表示删除。 ↩︎

  • 1
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
路径分析是指在地理信息系统中,根据给定的起点和终点,在网络数据中找到最佳或最短的路径。在本例中,我们将使用PostgreSQL数据库、GeoServerOpenLayers实现路径分析。 首先,我们需要将网络数据导入PostgreSQL数据库。我们可以使用PostGIS插件来处理空间数据,它提供了丰富的空间分析功能。将网络数据导入数据库后,我们可以使用SQL查询进行路径分析。 接下来,我们需要将数据库中的数据发布到GeoServer中。GeoServer是一个开源的地理信息服务器,它可以将数据库中的空间数据发布为Web服务。通过GeoServer,我们可以将网络数据以WMS或WFS的形式发布出去,供OpenLayers进行可视化展示和交互。 最后,我们可以使用OpenLayers来在Web页面中显示地图,并实现路径分析的可视化。OpenLayers是一个开源的JavaScript库,它提供了丰富的地图显示和交互功能。我们可以使用OpenLayers的API来加载GeoServer发布的网络数据,并通过JavaScript代码来实现路径分析的功能。例如,我们可以在地图上绘制起点和终点,并使用OpenLayers的路线计算函数来找到最佳路径,并将其显示在地图上。 在整个过程中,PostgreSQL提供了数据存储和查询的功能,GeoServer提供了数据发布的功能,而OpenLayers提供了地图的可视化和交互功能。通过这些工具的结合,我们可以实现路径分析的功能,从而为用户提供最佳或最短路径的查询和展示。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值