摘要:注意的版本號(hào),高版本存在中新語法不兼容的情況查詢類型點(diǎn)擊多邊形拉框圖層名稱,可以是單個(gè)或多個(gè)重點(diǎn),不要改變回調(diào)函數(shù)聲明加載函數(shù)傳參解決跨域的關(guān)鍵回調(diào)回調(diào)函數(shù)使用載入要素用于刪除之前的框,表示號(hào),隨便取一個(gè)刪除之前的部分
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>OpenLayers</title> <link rel="stylesheet" href="geoserver/ol.css" type="text/css"> <script src="geoserver/ol.js"></script> <script src="bower_components/jquery/dist/jquery.min.js"></script> <link rel="stylesheet" href="plugins/layui-v2.4.3/layui/css/layui.css"> <script src="plugins/layui-v2.4.3/layui/layui.js" charset="utf-8"></script> <link rel="stylesheet" href="https://openlayers.org/en/v3.20.1/css/ol.css" type="text/css"> <#--注意openlayer的版本號(hào),高版本存在es6中新語法不兼容的情況--> <script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL"></script> <script src="https://openlayers.org/en/v3.20.1/build/ol.js"></script> </head> <style> #map { height: 600px; /*width: 1024px;*/ /* float: left;*/ } </style> <body> <div id="map"> <form class="form-inline"> <label>查詢類型</label> <select id="type"> <option value="None">None</option> <option value="Point">點(diǎn)擊</option> <option value="Polygon">多邊形</option> <option value="Circle">拉框</option> </select> </form> </div> <script> var map = new ol.Map({ target: 'map', view: new ol.View({ projection: 'EPSG:4326', center: [104.07, 30.72], zoom: 7 }) }); var wfsParams = { service: 'WFS', version: '1.1.1', request: 'GetFeature', typeName: 'map_dz:tl_lx_g', //圖層名稱,可以是單個(gè)或多個(gè) outputFormat: 'text/javascript', //重點(diǎn),不要改變 format_options: 'callback:loadFeatures' //回調(diào)函數(shù)聲明 }; var vectorSource = new ol.source.Vector({ format: new ol.format.GeoJSON(), loader: function (extent, resolution, projection) { //加載函數(shù) var url = 'http://192.168.1.113:8080/geoserver/map_dz/wms'; $.ajax({ url: url, data: $.param(wfsParams), //傳參 type: 'GET', dataType: 'jsonp', //解決跨域的關(guān)鍵 jsonpCallback: 'loadFeatures' //回調(diào) }); }, strategy: ol.loadingstrategy.tile(new ol.tilegrid.createXYZ({ maxZoom: 20 })), projection: 'EPSG:4326' }); //回調(diào)函數(shù)使用 window.loadFeatures = function (response) { vectorSource.addFeatures((new ol.format.GeoJSON()).readFeatures(response)); //載入要素 }; var vectorLayer = new ol.layer.Vector({ source: vectorSource, style: new ol.style.Style({ stroke: new ol.style.Stroke({ color: 'rgba(0, 0, 255, 1.0)', width: 2 }) }) }); map.addLayer(vectorLayer); var draw; var typeSelect = document.getElementById('type'); var value; var num=10;//用于刪除之前的框,表示號(hào),隨便取一個(gè) function addInteraction() { if (value !== 'None') { if (value === 'Polygon') { draw = new ol.interaction.Draw({ source: vectorLayer.getSource(), style: new ol.style.Style({ stroke: new ol.style.Stroke({ color: '#ffcc33', width: 2 }), image: new ol.style.Circle({ radius: 7, fill: new ol.style.Fill({ color: '#ffcc33' }) }) }), type: value }); } else if (value === 'Circle') { draw = new ol.interaction.Draw({ source: vectorLayer.getSource(), style: new ol.style.Style({ stroke: new ol.style.Stroke({ color: '#ffcc33', width: 2 }), image: new ol.style.Circle({ radius: 7, fill: new ol.style.Fill({ color: '#ffcc33' }) }) }), type: value, geometryFunction: ol.interaction.Draw.createBox() }); } else if (value === 'Point') { draw = new ol.interaction.Draw({ source: vectorLayer.getSource(), style: new ol.style.Style({ stroke: new ol.style.Stroke({ color: '#ffcc33', width: 2 }), image: new ol.style.Circle({ radius: 7, fill: new ol.style.Fill({ color: '#ffcc33' }) }) }), type: value }); } map.addInteraction(draw); //刪除之前draw的部分 draw.on('drawstart',function(evt) { var featureAdd=vectorLayer.getSource().getFeatureById(num); if(featureAdd!=null){ vectorLayer.getSource().removeFeature(featureAdd); } }); //繪圖結(jié)束,處理選中部分 draw.on('drawend',function(e){ e.feature.setId(num); var geom=e.feature.getGeometry(); var coor = geom.v; mapSelect(coor); }); } } //選擇事件 typeSelect.onchange = function() { value = typeSelect.value; map.removeInteraction(draw); addInteraction(); }; //draw圖像與原始數(shù)據(jù)相交 function mapSelect(coor) { if(value=='Point') { coor = [coor[0]-0.0001,coor[1]-0.0001,coor[0]+0.0001,coor[1]+0.0001]; } var FILTER = '<Filter xmlns:ogc="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml"><BBOX><PropertyName>geom</PropertyName><gml:Envelope srsName="EPSG:4326"><gml:lowerCorner>' + coor[0] + ' ' + coor[1] + '</gml:lowerCorner><gml:upperCorner>' + coor[2] + ' ' + coor[3] + '</gml:upperCorner></gml:Envelope></BBOX></Filter>'; getFeature({ typename: 'map_dz:tl_lx_g',//查詢的服務(wù)圖層名稱 filter: FILTER,//查詢條件 callback: 'getIdentifyroadGrid'//查詢的回調(diào)函數(shù) }); } var selectNum=[]; var geojsonFormat = new ol.format.GeoJSON({defaultDataProjection: "EPSG:4326"}); function getIdentifyroadGrid(res) { var queryData = []; var features = geojsonFormat.readFeatures(res); for (var nu = 0; nu<selectNum.length;nu++) { var featureSelect=vectorLayer.getSource().getFeatureById(selectNum[nu]); if(featureSelect!=null) { featureSelect.setStyle( new ol.style.Style({ stroke: new ol.style.Stroke({ color: 'rgba(0, 0, 255, 1.0)', width: 2 }) })); } } selectNum=[]; for (var i = 0; i < features.length; i++) { var feature = features[i]; console.log(feature); selectNum.push(feature.f); var featureSelectCurrent=vectorLayer.getSource().getFeatureById(feature.f); featureSelectCurrent.setStyle( new ol.style.Style({ stroke: new ol.style.Stroke({ color: '#ff4118', width: 2 }) })); var lxmc = feature.H["lxmc"]; var ldbm = feature.H["ldbm"]; var lxbh = feature.H["lxbh"]; var result = { "lxmc": lxmc, "ldbm": ldbm, "lxbh": lxbh, "setindex": i }; queryData.push(result) } console.log(selectNum); var tableIns=null; var dataTable = "<table class="layui-table" lay-filter="demo" id="joinTab"></table>"; layui.use(['table', 'layer'], function () { var table = layui.table; var layer = layui.layer; var index = layer.open({ type: 1 //Page層類型 , title: '要素屬性' , shade: 0 //遮罩透明度 , anim: 0 //0-6的動(dòng)畫形式,-1不開啟 , content: dataTable , offset: ['250px', '290px'] , zIndex: 1 , scrollbar: false , resize: false , skin: 'layui-layer-molv' , closeBtn: 2 , btn: ["關(guān)閉"] , yes: function (index) { layer.close(index); } , cancel: function () { } }); tableIns = table.render({ elem: "#joinTab", width: "auto", height: "auto", data: queryData, initSort: {field: 'lxbh', type: 'desc'}, cols: [[ {field: 'lxmc', title: '路線名稱', width: 150, align: 'center', sort: true}, {field: 'ldbm', title: '路線編號(hào)', width: 150, align: 'center', sort: true}, {field: 'lxbh', title: '路段編碼', width: 150, align: 'center', sort: true} ]] }); layer.style(index, { opacity: 0.8 }); }); if (tableIns) { tableIns.reload({ data: queryData }); } else { // console.log("Do Nothing!"); } } //請求wfs數(shù)據(jù) function getFeature(options) { $.ajax(/*'http://192.168.1.113:8080/geoserver/map_dz/wms', */{ type: 'GET', url: 'http://192.168.1.113:8080/geoserver/map_dz/wms', data: { service: 'WFS', version: '1.1.1', request: 'GetFeature', typename: options.typename, srsname: options.srid, outputFormat: 'text/javascript', viewparams: options.viewparams, bbox: (options.extent === undefined) ? undefined : options.extent.join(',') + ',' + options.srid, filter: options.filter }, dataType: 'jsonp', jsonp: 'format_options', jsonpCallback: 'callback:' + options.callback }); } </script> </body> </html>
文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請注明本文地址:http://systransis.cn/yun/1130.html
摘要:小程序開發(fā)網(wǎng)站推薦微信小程序支付寶小程序百度智能小程序字符跳動(dòng)小程序小程序組件化開發(fā)框架開發(fā)小程序框架語法開發(fā)小程序框架,漸進(jìn)式應(yīng)用漸進(jìn)式應(yīng)用教程博客大牛推薦張鑫旭個(gè)人網(wǎng)站阮一峰網(wǎng)絡(luò)日志阮一峰教程廖雪峰官方網(wǎng)站呂大豹的博客司徒正美博客編程教 小程序開發(fā)網(wǎng)站推薦 微信小程序:https://developers.weixin.qq.... 支付寶小程序:https://open.al...
以下為個(gè)人目前接觸到的前端技術(shù),歡迎大家補(bǔ)充。 一、前端技術(shù)框架 1、Vue.js 官網(wǎng):https://cn.vuejs.org/ Vue CLI:https://cli.vuejs.org/ 菜鳥教程:http://www.runoob.com/w3cnote... Nuxt.js:https://zh.nuxtjs.org/ 桌面應(yīng)用Electron:https:...
小編寫這篇文章的主要目的,主要是來給大家做個(gè)詳細(xì)的解答,解答的內(nèi)容主要是Python的相關(guān)內(nèi)容,包括利用Python實(shí)現(xiàn)GeoServer矢量文件的批量發(fā)布,具體是怎么樣進(jìn)行操作呢?下面就給大家詳細(xì)解答下?! ?.前言 由于矢量圖層文件較多,手動(dòng)發(fā)布費(fèi)時(shí)費(fèi)力,python支持的關(guān)于geoserver包(geoserver-restconfig)又由于年久失修,無法在較新的geoserver版...
摘要:兩種方案中間件我沒搞成功把文件放進(jìn)去之后改好了報(bào),這個(gè)我沒搞成功就不多說了,需要的可以自行搜索一波。需要監(jiān)聽的項(xiàng)目所在端口號(hào)就比如我的項(xiàng)目啟動(dòng)端口是,這里就寫地址,本地和都可以項(xiàng)目中的路徑這個(gè)意思就是在項(xiàng)目中訪問的時(shí)候把請求轉(zhuǎn)到是轉(zhuǎn)發(fā)地址 兩種方案 coess中間件(我沒搞成功) 把class文件放進(jìn)去之后改好了web.xml報(bào)504,這個(gè)我沒搞成功就不多說了,需要的可以自...
閱讀 740·2023-04-25 19:43
閱讀 3986·2021-11-30 14:52
閱讀 3816·2021-11-30 14:52
閱讀 3873·2021-11-29 11:00
閱讀 3809·2021-11-29 11:00
閱讀 3907·2021-11-29 11:00
閱讀 3584·2021-11-29 11:00
閱讀 6197·2021-11-29 11:00