赞
踩
目录
测试代码发现 插入图斑其图形经纬度是正常的经纬度插入 图形更新他妈就变成需要纬经度,所以涉及一个applyTransform 调换经纬度坐标,以符合wfs协议中经纬度的位置
- <template>
- <!--地图挂载dom-->
- <div id="map">
- </div>
- </template>
- <script>
-
-
- //引入依赖
- import { ImageWMS, TileWMS } from 'ol/source'
- import MultiPolygon from 'ol/geom/MultiPolygon.js';
- import { Feature, Map, View, geom } from 'ol';
- import XYZ from 'ol/source/XYZ';
- import { Circle as CircleStyle, Fill, Stroke, Style } from 'ol/style';
- import { Vector as VectorSource } from 'ol/source'
- import { Image as ImageLayer, Tile as TileLayer, Vector as VectorLayer } from 'ol/layer';
- import { Polygon } from 'ol/geom'
- import * as turf from '@turf/turf';
- import { GeoJSON, WFS, GML } from 'ol/format';
- import turfData from '../data/turfIntersectData';
- import { Draw, Select, Modify } from 'ol/interaction';
-
- export default {
- data() {
- return {
- map: null
- }
- },
- mounted() {
- let _this = this;
- //初始化地图
- this.map = new Map({
- target: 'map',//指定挂载dom,注意必须是id
- layers: [
- new ImageLayer({
- opacity: 0.1, //图层透明度
- source: new ImageWMS({
- ratio: 1,
- url: 'http://192.168.10.17:8080/geoserver/custom/wms',
- params: {
- 'FORMAT': 'image/png',
- 'VERSION': '1.1.1',
- "STYLES": '',
- "LAYERS": 'custom:JGSQGW_Geo',
- "exceptions": 'application/vnd.ogc.se_inimage',
- }
- })
- }),
- ],
- //配置视图
- view: new View({
- //--start-#视图中心位置#-->
- center: [115.794692, 28.621057],
- //--start-#指定坐标系,4326为wgs84地理坐标系统#-->4490
- projection: "EPSG:4326",
- zoom: 12
- })
- });
- this.map.getView().fit([115.77521, 28.18268,
- 115.79453, 28.20572], this.map.getSize());
-
-
- // var url1 = "http://localhost:8090/geoserver/HT/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=HT%3Acrud_zhen&maxFeatures=50&outputFormat=application%2Fjson"
- var polygonSource = new VectorSource({
- url:
- "http://192.168.10.162:8080/geoserver/wfs?" +
- "service=WFS&" +
- "version=1.1.0&" +
- "request=GetFeature&" +
- "typeNames= custom:JGSQGW_Geo&" +
- "outputFormat=json&" +
- "srsname=EPSG:4490",
- format: new GeoJSON({
- geometryName: "geom" // postgis的空间存储字段名
- })
- });
- var polygonLayer = new VectorLayer({
- source: polygonSource,
- style: new Style({
- stroke: new Stroke({
- color: '#0000ff',
- width: 2
- })
- })
- });
- this.map.addLayer(polygonLayer);
-
-
- // 绘制控件
- let drawedFeatures = [];
- let draw = new Draw({
- source: polygonLayer.getSource(),
- type: 'MultiPolygon',
- geometryName: 'geom' // 注意:这里图形信息字段一定要和后端服务器一致
- });
-
- draw.on('drawend', (event) => {
-
-
- console.log("drawend", event.feature.getGeometry().getCoordinates());
- let ft = new Feature();
- // let properties = polygonLayer.getSource().getFeatures()[0].getProperties();
- //delete properties.geom;
- let properties = {};
- properties.gridone = '大哥向东12';
- properties.gridtwo = '388向东12';
- ft.setProperties(properties);
-
- let geom = event.feature.getGeometry().clone();
- // 调换经纬度坐标,以符合wfs协议中经纬度的位置
- // geom.applyTransform((flatCoordinates, flatCoordinates2, stride) => {
- // for (var j = 0; j < flatCoordinates.length; j += stride) {
- // var y = flatCoordinates[j]
- // var x = flatCoordinates[j + 1]
- // flatCoordinates[j] = x
- // flatCoordinates[j + 1] = y
- // }
- // })
- console.log("geom", geom.getCoordinates());
- ft.setGeometryName('geom');// 一定要放在setGemetry之前
- ft.setGeometry(geom);
-
- _this.transact_crud("insert", ft, "www.custom.com", "custom", ["JGSQGW_Geo"], "EPSG:4490");
-
-
- // let ft = new Feature();
-
- // let properties = polygonLayer.getSource().getFeatures()[0].getProperties();
- // delete properties.geom;
- // properties.gridone = '大哥向东';
- // properties.gridtwo = '388向东';
- // ft.setProperties(properties);
-
- // let geom = event.feature.getGeometry().clone()
-
-
-
- // let feature2 = event.feature;
- // // console.log("drawend",feature.getGeometry().getCoordinates());
- // console.log("drawend", feature);
-
- // // var feature1 = new Feature({
- // // geom: new ol.geom.MultiPolygon([antitone])
- // // });
- // console.log(event.feature.getGeometry().getCoordinates());
- // var points = event.feature.getGeometry().getCoordinates();
-
- // var antitone = [[]];
- // points[0].map(function (val, index) {
- // //var point = new proj.toLonLat(val);
- // // antitone[0].push([point[1], point[0]]);
- // antitone[0].push([val[1], val[0]]);
- // });
-
-
- // // let ft = new Feature()
- // // ft.setGeometryName('geom')
- // // ft.setGeometry(new MultiPolygon([antitone]));
- // // ft.set("gridone", "大哥向东"); //这里可以设置其他属性
-
-
-
- // var feature = new Feature({
- // // geometry: new MultiPolygon([antitone]),
- // geometry: new MultiPolygon(points),
- // //geometry: new Polygon([antitone])
- // });
-
-
-
-
- // let properties = polygonLayer.getSource().getFeatures()[0].getProperties()
- // console.log("properties", properties);
- // delete properties.geom;
-
- // console.log("properties2", properties);
- // properties.gridone = '大哥向东';
- // properties.gridtwo = '小弟向下';
- // ft.setProperties(properties)
-
- // let geom = feature.getGeometry().clone()
- // ft.setGeometryName('geom') // 一定要放在setGemetry之前
- // ft.setGeometry(geom)
-
- // //为要素添加属性,我这里随便设置属性
- // feature.set('gridone', '大哥向东');
- // // // let ft = new ol.Feature();
- // // // let ft = new Feature();
- // feature.set('gridtwo', '小弟向下');
-
- // console.log("ft_feature", feature);
-
-
-
- // let properties = polygonLayer.getSource().getFeatures()[0].getProperties();
- // //let geom = feature.getGeometry()
- // properties.type = 'road'
- // properties.type1 = 'road1'
- // delete properties.type1
- // console.log("properties", properties);
- // console.log("properties222", polygonLayer.getSource().getFeatures()[0]);
-
- // drawedFeatures.push(event.feature);
- // console.log("event.feature", event.feature);
- // _this.addFeatureWFS(drawedFeatures);
- // _this.transact_crud("insert", event.feature, "www.custom.com", "custom", ["JGSQGW_Geo"], "EPSG:4490");
- // _this.transact_crud("insert", ft, "www.custom.com", "custom", ["JGSQGW_Geo"], "EPSG:4490");
- });
- this.map.addInteraction(draw);
- draw.setActive(true);
-
-
- },
- computed: {
-
- },
- methods: {
- // transType为增删改类型
- // feat为要增删改的要素
- transact_crud(transType, feat, featureNS, featurePrefix, featureType, srsName) {
- if (featureNS == "" || featurePrefix == "" || featureType == "" || srsName == "") {
- return;
- }
- var formatWFS = new WFS();
- var formatGML = new GML({
- featureNS,
- featurePrefix,
- featureType,
- gmlOptions: { srsName }
- });
- let transact_xml = null;
- switch (transType) {
- case "insert":
- transact_xml = formatWFS.writeTransaction([feat], null, null, formatGML);
- break;
- case "update":
- transact_xml = formatWFS.writeTransaction(null, [feat], null, formatGML);
- break;
- case "delete":
- transact_xml = formatWFS.writeTransaction(null, null, [feat], formatGML);
- break;
- }
- let transact_str = (new XMLSerializer()).serializeToString(transact_xml);
-
- // 使用Fetch将请求发送到后端
- fetch('http://192.168.10.162:8080/geoserver/wfs', {
- method: 'POST',
- body: transact_str,
- headers: {
- 'Content-Type': 'text/xml'
- }
- }).then(res => res.text()).then(res => {
- // let transactRes = WFS.readTransactionResponse(res);
- // let str = transactRes.transactionSummary.totalInserted +
- // " totalInserted!, insertIds: " + transactRes.insertIds + "\n";
- // str += transactRes.transactionSummary.totalUpdated + " totalUpdated!\n";
- // str += transactRes.transactionSummary.totalDeleted + " totalDeleted!";
- // alert(str);
- });
-
-
- },
-
- addFeatureWFS(features) {
- let WFSGML = new WFS();
- // 生成XML格式的WFS请求信息
- let transact_xml = WFSGML.writeTransaction(features, null, null, {
- srcName: 'EPSG:4490',
- featureNS: "www.custom.com",
- featurePrefix: "custom",
- featureType: ["JGSQGW_Geo"],
- }
- );
- // 将XML格式请求信息序列化为字符串格式
- let transact_str = (new XMLSerializer()).serializeToString(transact_xml);
- // 使用Fetch将请求发送到后端
- fetch('http://192.168.10.162:8080/geoserver/wfs', {
- method: 'POST',
- body: transact_str,
- headers: {
- 'Content-Type': 'text/xml'
- }
- }).then(res => res.text()).then(res => {
- let transactRes = WFS.readTransactionResponse(res);
- let str = transactRes.transactionSummary.totalInserted +
- " totalInserted!, insertIds: " + transactRes.insertIds + "\n";
- str += transactRes.transactionSummary.totalUpdated + " totalUpdated!\n";
- str += transactRes.transactionSummary.totalDeleted + " totalDeleted!";
- alert(str);
- });
- },
-
-
-
-
-
- // feat为要增删改的要素
- // layerName为要进行操作的目标图层名称
- transact(feature, layerName) {
- if (layerName == "") {
- return;
- }
- // 将选中的要素序列化为字符串格式
- var formatWFS = new WFS();
- var formatGML = new GML({
- featureNS: "www.custom.com",
- featurePrefix: "custom",
- featureType: ["JGSQGW_Geo"],
- gmlOptions: { srsName: "EPSG:4490" }
- });
- let transact_str = formatWFS.writeTransaction(null, null, [feature], formatGML);
-
- fetch('http://192.168.10.162:8080/geoserver/wfs', {
- method: 'POST',
- body: new XMLSerializer().serializeToString(featureRequest),
- headers: {
- 'Content-Type': 'text/xml'
- }
- }).then((response) => {
- console.log("response", response);
- return response.text();
- })
- .then((res) => {
- let transactRes = formatWFS.readTransactionResponse(res);
- let str = transactRes.transactionSummary.totalInserted +
- " totalInserted!, insertIds: " + transactRes.insertIds + "\n";
- str += transactRes.transactionSummary.totalUpdated + " totalUpdated!\n";
- str += transactRes.transactionSummary.totalDeleted + " totalDeleted!";
- alert(str);
- });
-
- },
-
-
- },
- }
- </script>
- <style scoped>
- #map {
- width: 100%;
- height: 100%;
- }
- </style>
- <template>
- <!--地图挂载dom-->
- <div id="map">
- <div class="btn">
- <el-button type="success" @click="updateFeature">111</el-button>
- </div>
- </div>
- </template>
- <script>
-
-
- //引入依赖
- import { ImageWMS, TileWMS } from 'ol/source'
-
- import { Feature, Map, View } from 'ol';
- import XYZ from 'ol/source/XYZ';
- import { Circle as CircleStyle, Fill, Stroke, Style } from 'ol/style';
- import { Vector as VectorSource } from 'ol/source'
- import { Image as ImageLayer, Tile as TileLayer, Vector as VectorLayer } from 'ol/layer';
- import { Polygon } from 'ol/geom'
- import * as turf from '@turf/turf';
- import { GeoJSON, WFS, GML } from 'ol/format';
- import turfData from '../data/turfIntersectData';
- import { Draw, Select, Modify } from 'ol/interaction';
-
- export default {
- data() {
- return {
- map: null,
- modifiedFeatures: []
- }
- },
- mounted() {
- let _this = this;
- //初始化地图
- this.map = new Map({
- target: 'map',//指定挂载dom,注意必须是id
- layers: [
- new ImageLayer({
- opacity: 0.1, //图层透明度
- source: new ImageWMS({
- ratio: 1,
- url: 'http://192.168.10.162:8080/geoserver/custom/wms',
- params: {
- 'FORMAT': 'image/png',
- 'VERSION': '1.1.1',
- "STYLES": '',
- "LAYERS": 'custom:JGSQGW_Geo',
- "exceptions": 'application/vnd.ogc.se_inimage',
- }
- })
- }),
- ],
- //配置视图
- view: new View({
- //--start-#视图中心位置#-->
- center: [115.794692, 28.621057],
- //--start-#指定坐标系,4326为wgs84地理坐标系统#-->4490
- projection: "EPSG:4326",
- zoom: 12
- })
- });
- this.map.getView().fit([115.77521, 28.18268,
- 115.79453, 28.20572], this.map.getSize());
-
-
- // var url1 = "http://localhost:8090/geoserver/HT/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=HT%3Acrud_zhen&maxFeatures=50&outputFormat=application%2Fjson"
- var polygonSource = new VectorSource({
- url:
- "http://192.168.10.162:8080/geoserver/wfs?" +
- "service=WFS&" +
- "version=1.1.0&" +
- "request=GetFeature&" +
- "typeNames= custom:JGSQGW_Geo&" +
- "outputFormat=json&" +
- "srsname=EPSG:4490",
- format: new GeoJSON({
- geometryName: "geom" // postgis的空间存储字段名
- })
- });
- var polygonLayer = new VectorLayer({
- source: polygonSource,
- style: new Style({
- stroke: new Stroke({
- color: '#0000ff',
- width: 2
- })
- })
- });
- this.map.addLayer(polygonLayer);
-
- // 选择要素控件
- let select = new Select({
- layers: [polygonLayer],
- hitTolerance: 10,
- style: new Style({
- stroke: new Stroke({
- color: 'red',
- width: 2
- })
- })
- });
- this.map.addInteraction(select);
-
- // 修改要素控件
- let modify = new Modify({
- features: select.getFeatures(),
- style: new Style({
- stroke: new Stroke({
- color: 'black',
- width: 2
- })
- }),
- });
-
- this.map.addInteraction(modify);
- modify.on("modifyend", function (e) {
- console.log("modifyend");
- var feature = e.features.item(0).clone();
- feature.setId(e.features.item(0).getId());
- var geomType = feature.getGeometry().getType().toLowerCase(); //openlayers绘制类型
- let geom = feature.getGeometry().getCoordinates();
- console.log("getCoordinates", geom);
- // 调换经纬度坐标,以符合wfs协议中经纬度的位置
- feature
- .getGeometry()
- .applyTransform(function (flatCoordinates, flatCoordinates2, stride) {
- for (var j = 0; j < flatCoordinates.length; j += stride) {
- var y = flatCoordinates[j];
- var x = flatCoordinates[j + 1];
- flatCoordinates[j] = x;
- flatCoordinates[j + 1] = y;
- }
- });
- console.log("getCoordinates2", feature.getGeometry().getCoordinates());
- _this.transact_crud("update", feature, "www.custom.com", "custom", "JGSQGW_Geo", "EPSG:4490");
- });
- },
- computed: {
-
- },
- methods: {
-
-
- updateFeature() {
- let _this = this;
- let features = [];
- this.modifiedFeatures.forEach(function (item, index, array) {
- console.log("item", item);
- features.push(item);
- //_this.updateWFS(features);
- _this.transact_crud("update", item, "www.custom.com", "custom", "JGSQGW_Geo", "EPSG:4490");
-
- });
-
- },
- updateWFS(features) {
- let WFSs = new WFS();
- // 生成XML格式的WFS请求信息
- let transact_xml = WFSs.writeTransaction(
- null, features, null,
- {
- srcName: 'EPSG:4490',
- featureNS: "www.custom.com",
- // featurePrefix: "custom",
- featureType: "JGSQGW_Geo",
- }
- )
- // 将XML格式请求信息序列化为字符串格式
- let transact_str = (new XMLSerializer()).serializeToString(transact_xml);
- // 使用Fetch将请求发送到后端
- fetch('http://192.168.10.162:8080/geoserver/wfs', {
- method: 'POST',
- body: transact_str,
- headers: {
- 'Content-Type': 'text/xml'
- }
- }).then(res => res.text()).then(res => {
- console.log(res);
- });
- }
- ,
- // transType为增删改类型
- // feat为要增删改的要素
- transact_crud(transType, feat, featureNS, featurePrefix, featureType, srsName) {
-
- if (featureNS == "" || featurePrefix == "" || srsName == "") {
- return;
- }
- var formatWFS = new WFS();
- var formatGML = new GML({
- featureNS,
- featurePrefix,
- featureType,
- gmlOptions: { srsName }
- });
- let transact_xml = null;
- switch (transType) {
- case "insert":
- transact_xml = formatWFS.writeTransaction([feat], null, null, formatGML);
- break;
- case "update":
- transact_xml = formatWFS.writeTransaction(null, [feat], null, formatGML);
- break;
- case "delete":
- transact_xml = formatWFS.writeTransaction(null, null, [feat], formatGML);
- break;
- }
- let transact_str = (new XMLSerializer()).serializeToString(transact_xml);
-
- // 使用Fetch将请求发送到后端
- fetch('http://192.168.10.162:8080/geoserver/wfs', {
- method: 'POST',
- body: transact_str,
- headers: {
- 'Content-Type': 'text/xml'
- }
- }).then(res => res.text()).then(res => {
-
- // let transactRes = WFS.readTransactionResponse(res);
- // let str = transactRes.transactionSummary.totalInserted +
- // " totalInserted!, insertIds: " + transactRes.insertIds + "\n";
- // str += transactRes.transactionSummary.totalUpdated + " totalUpdated!\n";
- // str += transactRes.transactionSummary.totalDeleted + " totalDeleted!";
- // alert(str);
- });
-
-
- },
-
- addFeatureWFS(features) {
- let WFSGML = new WFS();
- // 生成XML格式的WFS请求信息
- let transact_xml = WFSGML.writeTransaction(features, null, null, {
- srcName: 'EPSG:4490',
- featureNS: "www.custom.com",
- featurePrefix: "custom",
- featureType: ["JGSQGW_Geo"],
- }
- );
- // 将XML格式请求信息序列化为字符串格式
- let transact_str = (new XMLSerializer()).serializeToString(transact_xml);
- // 使用Fetch将请求发送到后端
- fetch('http://192.168.10.162:8080/geoserver/wfs', {
- method: 'POST',
- body: transact_str,
- headers: {
- 'Content-Type': 'text/xml'
- }
- }).then(res => res.text()).then(res => {
- let transactRes = WFS.readTransactionResponse(res);
- let str = transactRes.transactionSummary.totalInserted +
- " totalInserted!, insertIds: " + transactRes.insertIds + "\n";
- str += transactRes.transactionSummary.totalUpdated + " totalUpdated!\n";
- str += transactRes.transactionSummary.totalDeleted + " totalDeleted!";
- alert(str);
- });
- },
-
-
-
-
-
- // feat为要增删改的要素
- // layerName为要进行操作的目标图层名称
- transact(feature, layerName) {
- if (layerName == "") {
- return;
- }
- // 将选中的要素序列化为字符串格式
- var formatWFS = new WFS();
- var formatGML = new GML({
- featureNS: "www.custom.com",
- featurePrefix: "custom",
- featureType: ["JGSQGW_Geo"],
- gmlOptions: { srsName: "EPSG:4490" }
- });
- let transact_str = formatWFS.writeTransaction(null, null, [feature], formatGML);
-
- fetch('http://192.168.10.162:8080/geoserver/wfs', {
- method: 'POST',
- body: new XMLSerializer().serializeToString(featureRequest),
- headers: {
- 'Content-Type': 'text/xml'
- }
- }).then((response) => {
- console.log("response", response);
- return response.text();
- })
- .then((res) => {
- let transactRes = formatWFS.readTransactionResponse(res);
- let str = transactRes.transactionSummary.totalInserted +
- " totalInserted!, insertIds: " + transactRes.insertIds + "\n";
- str += transactRes.transactionSummary.totalUpdated + " totalUpdated!\n";
- str += transactRes.transactionSummary.totalDeleted + " totalDeleted!";
- alert(str);
- });
-
- },
-
-
- },
- }
- </script>
- <style scoped>
- #map {
- width: 100%;
- height: 100%;
-
- .btn {}
- }
- </style>
- <template>
- <!--地图挂载dom-->
- <div id="map">
- </div>
- </template>
- <script>
-
-
- //引入依赖
- import { ImageWMS, TileWMS } from 'ol/source'
-
- import { Feature, Map, View } from 'ol';
- import XYZ from 'ol/source/XYZ';
- import { Circle as CircleStyle, Fill, Stroke, Style } from 'ol/style';
- import { Vector as VectorSource } from 'ol/source'
- import { Image as ImageLayer, Tile as TileLayer, Vector as VectorLayer } from 'ol/layer';
- import { Polygon } from 'ol/geom'
- import * as turf from '@turf/turf';
- import { GeoJSON, WFS, GML } from 'ol/format';
- import turfData from '../data/turfIntersectData';
- import { Draw, Select } from 'ol/interaction';
- export default {
- data() {
- return {
- map: null
- }
- },
- mounted() {
- let _this = this;
- //初始化地图
- this.map = new Map({
- target: 'map',//指定挂载dom,注意必须是id
- layers: [
- new ImageLayer({
- opacity: 0.1, //图层透明度
- source: new ImageWMS({
- ratio: 1,
- url: 'http://192.168.10.162:8080/geoserver/custom/wms',
- params: {
- 'FORMAT': 'image/png',
- 'VERSION': '1.1.1',
- "STYLES": '',
- "LAYERS": 'custom:JGSQGW_Geo',
- "exceptions": 'application/vnd.ogc.se_inimage',
- }
- })
- }),
- ],
- //配置视图
- view: new View({
- //--start-#视图中心位置#-->
- center: [115.794692, 28.621057],
- //--start-#指定坐标系,4326为wgs84地理坐标系统#-->4490
- projection: "EPSG:4326",
- zoom: 12
- })
- });
- this.map.getView().fit([115.77521, 28.18268,
- 115.79453, 28.20572], this.map.getSize());
-
-
- // var url1 = "http://localhost:8090/geoserver/HT/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=HT%3Acrud_zhen&maxFeatures=50&outputFormat=application%2Fjson"
- var polygonSource = new VectorSource({
- url:
- "http://192.168.10.162:8080/geoserver/wfs?" +
- "service=WFS&" +
- "version=1.1.0&" +
- "request=GetFeature&" +
- "typeNames= custom:JGSQGW_Geo&" +
- "outputFormat=json&" +
- "srsname=EPSG:4490",
- format: new GeoJSON({
- geometryName: "geom" // postgis的空间存储字段名
- })
- });
- var polygonLayer = new VectorLayer({
- source: polygonSource
- });
- this.map.addLayer(polygonLayer);
-
-
- var select = new Select();
- this.map.addInteraction(select);
- // 选中要素后执行删除操作
- select.on("select", function (e) {
- // console.log("null11");
- if (select.getFeatures().getLength() == 0) {
- // console.log("null");
- } else {
- let featureId = e.target
- .getFeatures()
- .getArray()[0]
- .getId();
- var feature;
- // console.log("null", e.target.getFeatures());
- feature = polygonSource.getFeatureById(featureId);
- // 从地图删除
- polygonSource.removeFeature(feature);
- e.target.getFeatures().clear();
- // 从数据库删除
- _this.transact(feature, "JGSQGW_Geo");
- }
- });
-
-
-
- },
- computed: {
-
- },
- methods: {
- // feat为要增删改的要素
- // layerName为要进行操作的目标图层名称
- transact(feature, layerName) {
- if (layerName == "") {
- return;
- }
- // 将选中的要素序列化为字符串格式
- var formatWFS = new WFS();
- var formatGML = new GML({
- featureNS: "www.custom.com",
- featurePrefix: "custom",
- featureType: layerName,
- gmlOptions: { srsName: "EPSG:4490" }
- });
- var featureRequest = formatWFS.writeTransaction(null, null, [feature], formatGML);
- // var s = new XMLSerializer();
- // str = s.serializeToString(featureRequest);
- // 发送post请求获取图层要素
-
- // var aaa = '<?xml version="1.0" encoding="UTF-8"?><wfs:TransactionResponse xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:wfs="http://www.opengis.net/wfs" xmlns:gml="http://www.opengis.net/gml" xmlns:ogc="http://www.opengis.net/ogc" xmlns:ows="http://www.opengis.net/ows" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.1.0" xsi:schemaLocation="http://www.opengis.net/wfs http://192.168.10.17:8080/geoserver/schemas/wfs/1.1.0/wfs.xsd"><wfs:TransactionSummary><wfs:totalInserted>0</wfs:totalInserted><wfs:totalUpdated>0</wfs:totalUpdated><wfs:totalDeleted>1</wfs:totalDeleted></wfs:TransactionSummary><wfs:TransactionResults/><wfs:InsertResults><wfs:Feature><ogc:FeatureId fid="none"/></wfs:Feature></wfs:InsertResults></wfs:TransactionResponse>';
- // console.log("aaa", new XMLSerializer().serializeToString(aaa));
-
-
- fetch('http://192.168.10.17:8080/geoserver/wfs', {
- method: 'POST',
- body: new XMLSerializer().serializeToString(featureRequest),
- headers: {
- 'Content-Type': 'text/xml'
- }
- }).then((response) => {
- console.log("response", response);
- return response.text();
- })
- .then((res) => {
- let transactRes = formatWFS.readTransactionResponse(res);
- let str = transactRes.transactionSummary.totalInserted +
- " totalInserted!, insertIds: " + transactRes.insertIds + "\n";
- str += transactRes.transactionSummary.totalUpdated + " totalUpdated!\n";
- str += transactRes.transactionSummary.totalDeleted + " totalDeleted!";
- alert(str);
- const layers = this.map.getLayers().getArray();
- if (layers.length > 0) {
- layers.forEach((item) => {
- item.getSource().refresh(); //这句代码
- });
- }
- });
-
- },
-
-
- },
- }
- </script>
- <style scoped>
- #map {
- width: 100%;
- height: 100%;
- }
- </style>
- transact_crud(transType, feat, featureNS, featurePrefix, featureType, srsName) {
- if (featureNS == "" || featurePrefix == "" || featureType == "" || srsName == "") {
- return;
- }
- var formatWFS = new WFS();
- var formatGML = new GML({
- featureNS,
- featurePrefix,
- featureType,
- gmlOptions: { srsName }
- });
- let transact_xml = null;
- switch (transType) {
- case "insert":
- transact_xml = formatWFS.writeTransaction([feat], null, null, formatGML);
- break;
- case "update":
- transact_xml = formatWFS.writeTransaction(null, [feat], null, formatGML);
- break;
- case "delete":
- transact_xml = formatWFS.writeTransaction(null, null, [feat], formatGML);
- break;
- }
- let transact_str = (new XMLSerializer()).serializeToString(transact_xml);
-
- // 使用Fetch将请求发送到后端
- fetch('http://192.168.10.162:8080/geoserver/wfs', {
- method: 'POST',
- body: transact_str,
- headers: {
- 'Content-Type': 'text/xml'
- }
- }).then(res => res.text()).then(res => {
- // let transactRes = WFS.readTransactionResponse(res);
- // let str = transactRes.transactionSummary.totalInserted +
- // " totalInserted!, insertIds: " + transactRes.insertIds + "\n";
- // str += transactRes.transactionSummary.totalUpdated + " totalUpdated!\n";
- // str += transactRes.transactionSummary.totalDeleted + " totalDeleted!";
- // alert(str);
- });
-
-
- },
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。