一、更新区要素
update setFID
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><!-- 1、加载ol库 --><script src="../lib/include-openlayers-local.js"></script><script src="../js/Gaode.js"></script></head><body><!-- 2、创建地图容器 --><button onclick="updatePolygon()">更新</button><div id="map_container"></div><!-- 3、实例化对象 --><script>const docLayer = new Zondy.Map.Doc('', 'city', {ip: 'localhost',port: 6163})const map = new ol.Map({target: 'map_container',layers: [gaode, docLayer],view: new ol.View({projection: 'EPSG:4326',center: [114, 30],zoom: 4})})function updatePolygon(){/* 2.1 构建几何信息 */var pointObj = [];pointObj[0] = new Zondy.Object.Point2D(104,35.88); // 修改99.41为100pointObj[1] = new Zondy.Object.Point2D(99.41,26.82);pointObj[2] = new Zondy.Object.Point2D(108,26.82);pointObj[3] = new Zondy.Object.Point2D(108,35.88);//设置区要素的几何信息var gArc = new Zondy.Object.Arc(pointObj)//构成区要素折线var gAnyLine = new Zondy.Object.AnyLine([gArc])//构成区要素var gRegion = new Zondy.Object.GRegion([gAnyLine])//构成区要素的几何信息var fGeom = new Zondy.Object.FeatureGeometry({RegGeom:[gRegion]})/* 2.2 设置样式信息 */var cRegionInfo = new Zondy.Object.CRegionInfo({EndColor:1,FillColor:5,FillMode:0,OutPenWidth:1,OverMethod:0,PatAngle:1,PatColor:1,PatHeight:1,PatID:27,PatWidth:1})var graphicInfo = new Zondy.Object.WebGraphicsInfo({InfoType:3, //区RegInfo:cRegionInfo})/* 2.3 设置属性信息 *///设置区要素的属性信息var attValue = ["中地数码-成都",100,800]/* 2.4 构建区要素对象 *///创建一个新的区要素var newFeature = new Zondy.Object.Feature({fGeom:fGeom,GraphicInfo:graphicInfo,AttValue:attValue})newFeature.setFType(3)//++newFeature.setFID(2)/* 2.5 设置要素集 */var featureSet = new Zondy.Object.FeatureSet()var cAttValue = new Zondy.Object.CAttStruct({FldNumber:3,FldType:['string','float','int'],FldName:['name','area','num']})featureSet.AttStruct = cAttValue;featureSet.addFeature(newFeature)/* 2.6调用地图编辑服务接口 *///创建一个要素编辑服务对象var editDocFeature = new Zondy.Service.EditDocFeature('city',0,{ip:'localhost',port:'6163'})editDocFeature.update(featureSet,onSuccess)}function onSuccess(data) {if (data.succeed) {alert('更新成功')docLayer.refresh(); //重新加载地图文档} else {alert('更新失败')}}</script></body></html>
二、修改点
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><!-- 1、加载ol库 --><script src="../lib/include-openlayers-local.js"></script><script src="../js/Gaode.js"></script></head><body><!-- 2、创建地图容器 --><button onclick="updatePoint()">修改上海到东海</button><div id="map_container"></div><!-- 3、实例化对象 --><script>const docLayer = new Zondy.Map.Doc('', 'city', {ip: 'localhost',port: 6163})const map = new ol.Map({target: 'map_container',layers: [gaode, docLayer],view: new ol.View({projection: 'EPSG:4326',center: [114, 30],zoom: 4})})/* 添加一个点到数据库 */function updatePoint() {/* 2.1构建几何信息 *//* 创建一个点形状,描述点形状的几何信息 */var gpoint = new Zondy.Object.GPoint(130, 30.40) // 修改位置/* 设置当前点要素的几何信息 */var fGeom = new Zondy.Object.FeatureGeometry({PntGeom: [gpoint]})/* 2.2 设置样式信息 */var pointInfo = new Zondy.Object.CPointInfo({Angle: 0,Color: 8, //子图的颜色Space: 0,SymHeight: 5, //点的高度SymID: 31,SymWidth: 5 //点的宽度})/* 设置当点要素的图形参数信息 */var webGraphicInfo = new Zondy.Object.WebGraphicsInfo({InfoType: 1, //点PntInfo: pointInfo})/* 2.3 设置属性信息 *//* 设置添加点要素的属性信息 */var attValue = ['东海', '1005']/* 2.4 构建要素对象 */var feature = new Zondy.Object.Feature({fGeom: fGeom, //坐标--几何信息GraphicInfo: webGraphicInfo, //样式信息AttValue: attValue //属性})/* 设置要素为点要素点 -->1线 -->2面 -->3*/feature.setFType(1)feature.setFID(15) //++/* 2.5 设置要素集 *///创建一个要素数据集var featureSet = new Zondy.Object.FeatureSet()/* 设置属性结构 */var cAttStruct = new Zondy.Object.CAttStruct({FldName: ['name', 'id'], //属性的字段名FldNumber: 2, //属性的个数FldType: ['string', 'string'] //属性的类型})featureSet.AttStruct = cAttStruct/* 添加要素到要素数据集 */featureSet.addFeature(feature)/* 2.6 调用编辑服务接口 *//*创建一个编辑服务类第一个参数:服务的名称 第二参数:图层的名称*/var editService = new Zondy.Service.EditDocFeature('city', 2, {ip: 'localhost',port: '6163' //访问IGServer的端口号, .net为6163,Java为8089})//执行添加点要素功能editService.update(featureSet, onSuccess)}function onSuccess(data) {if (data.succeed) {alert('修改成功')docLayer.refresh(); //重新加载地图文档} else {alert('修改失败')}}</script></body></html>
三、修改线
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><!-- 1、加载ol库 --><script src="../lib/include-openlayers-local.js"></script><script src="../js/Gaode.js"></script></head><body><!-- 2、创建地图容器 --><button onclick="updateLine()">修改</button><div id="map_container"></div><!-- 3、实例化对象 --><script>const docLayer = new Zondy.Map.Doc('', 'city', {ip: 'localhost',port: 6163})const map = new ol.Map({target: 'map_container',layers: [gaode, docLayer],view: new ol.View({projection: 'EPSG:4326',center: [114, 30],zoom: 4})})/* 添加一个线到数据库 */function updateLine(){/* 2.1 构建几何信息 */var pointObj = []pointObj[0] = new Zondy.Object.Point2D(114,30);pointObj[1] = new Zondy.Object.Point2D(118,20); //修改/* 构成折线的弧度 */var gArc = new Zondy.Object.Arc(pointObj);/* 构成线的折线 */var gAnyLine = new Zondy.Object.AnyLine([gArc])/* 设置线要素的几何信息 */var gLine = new Zondy.Object.GLine(gAnyLine)/* 设置要素的几何信息 */var fGeom = new Zondy.Object.FeatureGeometry({LinGeom:[gLine]})/* 2.2 设置而样式信息 *///设置添加线要素的图形参数信息var clineInfo = new Zondy.Object.CLineInfo({Color:1, //子图的颜色号LinStyleID:0,LinStyleID2:19,LinWidth:0.1, //线宽Xscale:10,Yscale:10})//设置要素的图形参数var graphicInfo = new Zondy.Object.WebGraphicsInfo({InfoType:2, //线LinInfo:clineInfo})/* 2.3 设置属性信息 */var attValue = ['武广线',1289]/* 2.4 构建要素类*///创建一个线要素var newFeature = new Zondy.Object.Feature({fGeom:fGeom,GraphicInfo:graphicInfo,AttValue:attValue})//设置要为线要素newFeature.setFType(2)newFeature.setFID(5)/* 2.5 设置要素集 *///创建一个要素数据集var featureSet = new Zondy.Object.FeatureSet();//创建属性结构设置对象var cAttStruct = new Zondy.Object.CAttStruct({FldName:['name','length'],FldNumber:2,FldType:['string','double ']})//设置要素数据集的属性结构featureSet.AttStruct = cAttStruct;//将添加的线要素添加到属性数据集中featureSet.addFeature(newFeature);/* 2.6 调用地图编辑服务接口 *///创建一个地图编辑对象var editDocFeature = new Zondy.Service.EditDocFeature('city',1,{ip:'localhost',port:'6163'})editDocFeature.update(featureSet,onSuccess)}function onSuccess(data) {if (data.succeed) {alert('修改成功')docLayer.refresh(); //重新加载地图文档} else {alert('修改失败')}}</script></body></html>
