三、Openlayers3.20.1通過Geoserver刪除數(shù)據(jù)庫中的數(shù)據(jù)

一、操作結(jié)果

沒有操作前
操作后那個(gè)點(diǎn)沒有啦

二、操作代碼

<!DOCTYPE html>
<html>

<head>
    <title></title>
    <link href="ol.css" rel='stylesheet' />
    <script src="ol-debug.js" type="text/javascript"></script>
    <script src="jquery-3.1.1.js" type="text/javascript"></script>
    <style>
        * {
            margin: 0px;
            padding: 0px;
        }

        html,
        body,
        #map {
            width: 100%;
            height: 100%;
        }
    </style>
</head>

<body>
    <div style="position:absolute;top:95px;left:95px;z-index:20"><button id="updatePoint">刪除</button></div>
    <div id="map"></div>
    <script>
        var layer = new ol.layer.Tile({
            source: new ol.source.XYZ({
                url: 'http://www.google.cn/maps/vt?pb=!1m5!1m4!1i{z}!2i{x}!3i{y}!4i256!2m3!1e0!2sm!3i342009817!3m9!2szh-CN!3sCN!5e18!12m1!1e47!12m3!1e37!2m1!1ssmartmaps!4e0&token=32965'
            })
        });
        var vector = new ol.layer.Vector({
            source: new ol.source.Vector({
                url: "http://localhost:8080/geoserver/HBAJ/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=HBAJ:center_point&outputFormat=application%2Fjson",
                format: new ol.format.GeoJSON()
            }),
            style: new ol.style.Style({
                image: new ol.style.Circle({
                    fill: new ol.style.Fill({
                        color: "#ff0000"
                    }),
                    radius: 5
                })
            })
        });

        var view = new ol.View({
            center: new ol.proj.fromLonLat([120, 30]),
            zoom: 5
        });
        var map = new ol.Map({
            layers: [layer, vector],
            view: view,
            target: "map",
            logo: false
        })

        var select = new ol.interaction.Select();




        var format = new ol.format.WFS();

        var add = document.getElementById("updatePoint");
        add.addEventListener("click", function () {
            map.addInteraction(select);
        });

        var format = new ol.format.WFS();
        select.on('select', function (evt) {
            var feature = evt.selected[0];
            var point = new ol.proj.toLonLat(feature.getGeometry().getCoordinates());



            var xml = format.writeTransaction(null, null, [feature], {
                featureNS: "www.hbaj.com",
                featurePrefix: "HBAJ",
                featureType: "center_point"
            });
            var serializer = new XMLSerializer();
            var featString = serializer.serializeToString(xml);


            $.ajax({
                url: "http://localhost:8080/geoserver/HBAJ/wfs",
                type: "POST",
                data: featString,
                contentType: 'text/xml',
                success: function (req) {
                    var all = vector.getSource().getFeatures();
                    for (var m = 0, n = all.length; m < n; m++) {
                        if (all[m].getId() === feature.getId()) {
                            vector.getSource().removeFeature(all[m]);
                        }
                    }
                    select.getFeatures().clear();
                    console.log(req);
                }
            });
        });
    </script>
</body>

</html>

三、問題
問題:實(shí)在沒遇到什么問題,如果你遇到可以留言。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Android 自定義View的各種姿勢(shì)1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 179,048評(píng)論 25 709
  • 從今天起,我準(zhǔn)備更新一篇小說,叫<誰的眼淚化作滿天繁星>這是一篇我構(gòu)思了很久的小說,當(dāng)時(shí)已經(jīng)把這篇小說寫出來了,但...
    糜情閱讀 385評(píng)論 2 1
  • 第一次看到這個(gè)字眼,情不自禁就想到年幼時(shí)課堂的第一節(jié)美術(shù)課。畫顆綠樹畫個(gè)房子成了千古不變的教學(xué)課程。畫自己夢(mèng)寐以求...
    柏冬閱讀 222評(píng)論 0 1

友情鏈接更多精彩內(nèi)容