通过地图事件,调用中地的服务添加点要素
1、通过事件获取地图坐标2、根据坐标,向地图文档(mapgis数据库)添加点要素
<!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><script src="../../lib/include-openlayers-local.js"></script><script src="../../js/Gaode.js"></script></head><body><div id="map_container"></div><script>const docLayer = new Zondy.Map.Doc('', 'smart_city01', {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})})map.on('click',function(e){var coordinate = e.coordinate;addPoint(coordinate)})/* 添加一个点到数据库 */function addPoint(position) {/* 2.1构建几何信息 *//* 创建一个点形状,描述点形状的几何信息 */var gpoint = new Zondy.Object.GPoint(position[0],position[1])/* 设置当前点要素的几何信息 */var fGeom = new Zondy.Object.FeatureGeometry({PntGeom: [gpoint]})/* 2.2 设置样式信息 */var pointInfo = new Zondy.Object.CPointInfo({Angle: 0,Color: 2, //子图的颜色Space: 0,SymHeight: 5, //点的高度SymID: 31,SymWidth: 5 //点的宽度})/* 设置当点要素的图形参数信息 */var webGraphicInfo = new Zondy.Object.WebGraphicsInfo({InfoType: 1, //点PntInfo: pointInfo})/* 2.3 设置属性信息 *//* 设置添加点要素的属性信息 */var attValue = ['上海']/* 2.4 构建要素对象 */var feature = new Zondy.Object.Feature({fGeom: fGeom, //坐标--几何信息GraphicInfo: webGraphicInfo, //样式信息AttValue: attValue //属性})/* 设置要素为点要素点 -->1线 -->2面 -->3*/feature.setFType(1)/* 2.5 设置要素集 *///创建一个要素数据集var featureSet = new Zondy.Object.FeatureSet()/* 设置属性结构 */var cAttStruct = new Zondy.Object.CAttStruct({FldName: ['name'], //属性的字段名FldNumber: 1, //属性的个数FldType: ['string'] //属性的类型})featureSet.AttStruct = cAttStruct/* 添加要素到要素数据集 */featureSet.addFeature(feature)/* 2.6 调用编辑服务接口 *//*创建一个编辑服务类第一个参数:服务的名称 第二参数:图层的名称*/var editService = new Zondy.Service.EditDocFeature('smart_city01', 0, {ip: 'localhost',port: '6163' //访问IGServer的端口号, .net为6163,Java为8089})//执行添加点要素功能editService.add(featureSet, onPntSuccess)}function onPntSuccess(data) {if (data.succeed) {alert('添加成功')docLayer.refresh(); //重新加载地图文档} else {alert('添加点要素失败')}}</script></body></html>
