geoserver三维_cesium结合geoserver利用WFS服务实现图层编辑(附源码下载)

本文展示了如何利用Cesium库结合GeoServer的WFS服务,实现在三维场景中加载并编辑图层。首先创建了geojson图层样式,然后加载GeoServer的WMS服务。通过监听屏幕点击事件,获取坐标并调用WFS服务进行点查询。当点击地图时,显示相关信息,并提供编辑功能,允许用户更新图层属性。
摘要由CSDN通过智能技术生成

//绘制geojson图层样式

var geoJsonStyle ={

stroke: Cesium.Color.YELLOW,

strokeWidth:3,

fill: Cesium.Color.YELLOW.withAlpha(0.1)

};var geoserverUrl = 'http://localhost:8080/geoserver/WebGIS';var image_Source = newCesium.UrlTemplateImageryProvider({//url: 'http://mt0.google.cn/vt/lyrs=t,r&hl=zh-CN&gl=cn&x={x}&y={y}&z={z}',//url: 'https://server.arcgisonline.com/arcgis/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}',

url: "http://map.geoq.cn/ArcGIS/rest/services/ChinaOnlineStreetPurplishBlue/MapServer/tile/{z}/{y}/{x}",//tilingScheme : new Cesium.GeographicTilingScheme(),

credit: ''});var viewer = new Cesium.Viewer('map', {

geocoder:false,

homeButton:false,

sceneModePicker:false,

fullscreenButton:false,

vrButton:false,

baseLayerPicker:false,

infoBox:false,

selectionIndicator:false,

animation:false,

timeline:false,

shouldAnimate:true,

navigationHelpButton:false,

navigationInstructionsInitiallyVisible:false,

imageryProvider: image_Source

});//加载geoserver wms服务

var wms = newCesium.WebMapServiceImageryProvider({

url: geoserverUrl+'/wms',

layers:'WebGIS:testLayer',

parameters: {

service :'WMS',

format:'image/png',

transparent:true,

}

});

viewer.imageryLayers.addImageryProvider(wms);

viewer._cesiumWidget._creditContainer.style.display= "none";

viewer.scene.globe.enableLighting= false;//viewer.scene.globe.depthTestAgainstTerrain = true;

viewer.scene.globe.showGroundAtmosphere = false;

viewer.camera.flyTo({

destination : Cesium.Cartesian3.fromDegrees(113.90271877, 22.95186415,30000.0)

});var handler = newCesium.ScreenSpaceEventHandler(viewer.scene.canvas);var ellipsoid =viewer.scene.globe.ellipsoid;

handler.setInputAction(function(movement) {//通过指定的椭球或者地图对应的坐标系,将鼠标的二维坐标转换为对应椭球体三维坐标

cartesian =viewer.camera.pickEllipsoid(movement.position, ellipsoid);if(cartesian) {//将笛卡尔坐标转换为地理坐标

var cartographic =ellipsoid.cartesianToCartographic(cartesian);//将弧度转为度的十进制度表示

var longitudeString =Cesium.Math.toDegrees(cartographic.longitude);var latitudeString =Cesium.Math.toDegrees(cartographic.latitude);var point = longitudeString + ',' +latitudeString;

queryByPoint(point,'testLayer',callbackLastQueryWFSService);

}

}, Cesium.ScreenSpaceEventType.LEFT_CLICK);/*点查图层

*@method queryByPoint

*@param point 点查

*@param typeName 图层名称

*@return null*/

functionqueryByPoint(point, typeName, callback){var filter =

'';

filter+= '';

filter+= 'the_geom';

filter+= '';

filter+= '' + point + '';

filter+= '';

filter+= '';

filter+= '';var urlString = geoserverUrl + '/ows';var param ={

service:'WFS',

version:'1.0.0',

request:'GetFeature',

typeName: typeName,

outputFormat:'application/json',

filter: filter

};var geojsonUrl = urlString +getParamString(param, urlString);

$.ajax({

url: geojsonUrl,

async:true,

type:'GET',

dataType:'json',

success(result) {

callback(result);

},

error(err) {

console.log(err);

}

})

}functiongetParamString(obj, existingUrl, uppercase){var params =[];for (var i inobj) {

params.push(encodeURIComponent(uppercase? i.toUpperCase() : i) + '=' +encodeURIComponent(obj[i]));

}return ((!existingUrl || existingUrl.indexOf('?') === -1) ? '?' : '&') + params.join('&');

}/** 点查图层回调函数*/

functioncallbackLastQueryWFSService(data){

console.log('data',data);if(data && data.features.length>0){

clearGeojsonLayer();

loadGeojsonLayer(data);//气泡窗口显示

var properties = data.features[0].properties;var id = data.features[0].id;var geometry = data.features[0].geometry;//var content = '名称:'+properties.estate_num+'备注:'+properties.holder_nam;

var content = '名称:备注:编辑';

$("#infowindow").show();

$("#infowindow").empty();

$("#infowindow").append(content);

$("#editBtn").click(function(){//console.log('编辑按钮点击事件');

if(id)

{//构造polygon

var polygon = '';var data = geometry.coordinates[0][0];for(var i=0;i

polygon+= item[0] + ',' + item[1] + ' ';

}

polygon+= data[0][0] + ',' + data[0][1];//只编辑属性信息,默认图形信息不变,感兴趣的,读者你们可自行编辑图形变化信息,这里预留图形参数传值了的

editLayers(id,polygon,$("#estate_num").val(),$("#holder_nam").val(),callbackEditLayersWFSService);

}

});

}else{//clearMap();

$("#infowindow").hide();

}

}/** 绘制图形函数*/

functionloadGeojsonLayer(geojson){var promise =Cesium.GeoJsonDataSource.load(geojson,geoJsonStyle);

promise.then(function(dataSource) {

viewer.dataSources.add(dataSource);//viewer.zoomTo(dataSource);

}).otherwise(function(error){

window.alert(error);

});

}/** 清空绘制图形函数*/

functionclearGeojsonLayer(){

viewer.dataSources.removeAll();

}functionclearMap(){if(drawTool) {

drawTool.destroy();

}

clearGeojsonLayer();

}/*图层编辑

*@method editLayers

*@param polygon 图形

*@param fid 记录fid值

*@param fieldValue1 字段1值

*@param fieldValue2 字段2值

*@return callback*/

functioneditLayers(fid,polygon,fieldValue1,fieldValue2, callback){var xml = '';

xml+= '';

xml+= '';

xml+= 'the_geom';……

……}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,我明白了。关于您的问题,我可以回答:Cesium是一个基于WebGL的虚拟地球和地理信息系统(GIS)库,可以用来展示地球上的各种数据,包括矢量图、卫星影像、地形模型等等。而Geoserver是一个开源的地理信息系统服务器,可以提供各种地图服务,包括WFS服务。 通过将CesiumGeoserver结合起来,我们可以实现矢量图的编辑,具体步骤如下: 1. 首先,需要在Geoserver上创建一个WFS数据源,并发布一个WFS服务。这里不再赘述具体的步骤,可以参考Geoserver的官方文档。 2. 在Cesium中,可以使用Cesium的DataSource来加载WFS服务中的图层数据。具体步骤如下: ```js // 创建一个DataSource var dataSource = new Cesium.GeoJsonDataSource(); // 加载WFS服务中的数据 var promise = dataSource.load('http://localhost:8080/geoserver/wfs', { service: 'WFS', version: '2.0.0', request: 'GetFeature', typeName: 'myworkspace:mylayer', outputFormat: 'application/json' }); // 数据加载完成后,将数据源添加到场景中 promise.then(function() { viewer.dataSources.add(dataSource); }); ``` 3. 接下来,可以使用Cesium的Entity来表示每个要素,并添加一些编辑功能。例如,可以使用Cesium的PolylineGraphics来表示线要素,并添加编辑功能。 ```js // 创建一个线要素 var entity = dataSource.entities.add({ polyline: { positions: Cesium.Cartesian3.fromDegreesArray([ -110.0, 38.0, -105.0, 40.0 ]), width: 5, material: Cesium.Color.RED } }); // 添加编辑功能 entity.polyline.editable = true; entity.polyline.width = 10; entity.polyline.material = Cesium.Color.BLUE; ``` 4. 最后,可以监听Cesium编辑事件,将编辑结果保存回Geoserver中。 ```js // 监听编辑事件 dataSource.entities.collectionChanged.addEventListener(function(collection, added, removed, changed) { // 将编辑结果保存回Geoserver中 // ... }); ``` 以上是实现矢量图编辑的大致步骤,具体的实现可能会因为数据源的不同而有所差异。希望对您有所帮助。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值