iServer与WebGL结合之三维矢量及模型数据更新操作

nannan

        在许多应用场景中需要对数据进行更新操作,包括对数据添加、删除、修改,以及属性数据的修改。当前10i版本的iServer已经开始支持对三维的点、线、面以及模型进行更新操作(注:10i版本之前不支持,仅支持二维矢量数据更新),WebGL目前还没有直接的接口对接三维矢量及模型数据更新,但是可以通过对 features 资源执行 POST 请求完成对数据集中的要素进行添加、修改和删除操作。下面我们先看在iServer里怎样对三维矢量数据进行添加、修改和删除操作的

1.数据准备

        在iDesktop里制作三维点、线、面以及模型数据,分别新建字段赋予不同属性值,保存工作空间,在iServer里对该工作空间发布数据服务。如下图:
在这里插入图片描述

2.添加要素

在这里插入图片描述
        如上图箭头和数字标号所示,要素添加只需以上三步即可完成,关键点在”features 添加或更新要素必填”项的参数书写,下面来看各个三维数据POST请求体中的参数:
三维点添加:

[{
    "ID": 7,
    "fieldNames": [
        "SMID",
        "SMUSERID",
        "SMGEOMETRY",
        "NAMEP"
    ],
    "fieldValues": [
        "7",
        "0",
        "",
        "点添加"
    ],
   "geometry": {
        "center": null,
        "type": "POINT3D",
        "scaleZ": 1,
        "points": [{
            "x": 117.06,
            "y": 41.03,
            "z": 10
        }],
        "scaleX": 1,
        "scaleY": 1,
        "rotationX": 0,
        "rotationY": 0,
        "rotationZ": 0,
        "x": 117,
        "parts": [1],
        "y": 41,
        "z": 2,
        "style": null,
        "prjCoordSys": null,
        "position": {
            "x": 117.06,
            "y": 41.03,
            "z": 10
        },
        "id": 1,
        "partTopo": null
    },
}]

三维线添加:

[{
    "stringID": null,
    "fieldNames": [
        "SMID",
        "SMUSERID",
        "SMLENGTH",
        "SMTOPOERROR",
        "SMGEOMETRY",
        "NAMEL"
    ],
    "geometry": {
        "center": null,
        "type": "LINE3D",
        "scaleZ": 1,
        "points": [
            {
                "x": 117.02655667246991,
                "y": 41.04253076675004,
                "z": 2.2407621145248413E-6
            },
            {
                "x": 117.0414260209201,
                "y": 40.97125745940423,
                "z": -2.1420419216156006E-7
            }
        ],
        "scaleX": 1,
        "scaleY": 1,
        "rotationX": 0,
        "rotationY": 0,
        "rotationZ": 0,
        "parts": [2],
        "style": null,
        "prjCoordSys": null,
        "position": {
            "x": 117.033991346695,
            "y": 41.00689411307714,
            "z": -2.1420419216156006E-7
        },
        "id": 6,
        "partTopo": null
    },
    "fieldValues": [
        "6",
        "0",
        "8031.8315792779",
        "0",
        "",
        "线添加"
    ],
    "ID": 6
}]

三维面添加:

[{
    "stringID": null,
    "fieldNames": [
        "SMID",
        "SMUSERID",
        "SMAREA",
        "SMPERIMETER",
        "SMGEOMETRY",
        "NAME"
    ],
    "geometry": {
        "center": null,
        "type": "REGION3D",
        "scaleZ": 1,
        "points": [
            {
                "x": 117.0060774778058,
                "y": 41.02092796551436,
                "z": -5.122274160385132E-7
            },
            {
                "x": 116.99531110481529,
                "y": 41.008513626642866,
                "z": 3.4281983971595764E-6
            },
            {
                "x": 117.01618454044865,
                "y": 40.984799475411116,
                "z": 1.0831281542778015E-6
            },
            {
                "x": 117.02664288389398,
                "y": 40.99909763742507,
                "z": -1.5208497643470764E-6
            },
            {
                "x": 117.0060774778058,
                "y": 41.02092796551436,
                "z": -5.122274160385132E-7
            }
        ],
        "scaleX": 1,
        "scaleY": 1,
        "rotationX": 0,
        "rotationY": 0,
        "rotationZ": 0,
        "parts": [5],
        "style": null,
        "prjCoordSys": null,
        "position": {
            "x": 117.01168961480673,
            "y": 41.00286372046274,
            "z": 3.93204391002655E-7
        },
        "id": 7,
        "partTopo": null
    },
    "fieldValues": [
        "7",
        "0",
        "4843412.085079652",
        "9608.704238087794",
        "",
        "面添加"
    ],
    "ID": 7
}]

模型添加:

[{
    "stringID": null,
    "fieldNames": [
        "SMID",
        "SMUSERID",
        "SMINDEXKEY",
        "SMGEOMETRY",
        "NAME"
    ],
    "geometry": {
        "boundingBox": {
            "lower": {
                "x": 117.02495568156017,
                "y": 40.95957029610707,
                "z": -3.3071323457534163E-10
            },
            "upper": {
                "x": 117.02681344074459,
                "y": 40.964580079518015,
                "z": 20.000000000272507
            }
        },
        "filePath": null,
        "center": null,
        "type": "GEOMODEL3D",
        "scaleZ": 33.82698440551758,
        "points": null,
        "scaleX": 7.808070659637451,
        "scaleY": 27.884326934814453,
        "rotationX": 0,
        "rotationY": 0,
        "rotationZ": 0,
        "parts": null,
        "model": [
            4,
            0,
            0,
            0,
            115,
            51,
            109,
            0,
            120,
            -38,
            -123,
            -109,
            -47,
            78,
            -62,
            48,
            20,
            -122,
            -21,
            24,
            -125,
            -104,
            -8,
            4,
            -34,
            120,
            -31,
            37,
            -70,
            77,
            100,
            -96,
            89,
            -106,
            116,
            -94,
            -67,
            16,
            -116,
            17,
            95,
            -96,
            74,
            -63,
            69,
            -24,
            -56,
            6,
            -119,
            119,
            -34,
            -8,
            2,
            62,
            18,
            -17,
            -30,
            -125,
            120,
            86,
            54,
            56,
            -125,
            6,
            -70,
            -76,
            -3,
            -49,
            -23,
            -73,
            -10,
            63,
            -51,
            -10,
            91,
            33,
            -60,
            103,
            73,
            -68,
            -104,
            5,
            39,
            -57,
            -2,
            51,
            31,
            -117,
            94,
            60,
            76,
            51,
            -51,
            68,
            60,
            20,
            -71,
            120,
            -30,
            83,
            17,
            -72,
            -51,
            -114,
            -41,
            -12,
            92,
            -17,
            -38,
            -73,
            -117,
            -44,
            106,
            -75,
            43,
            -6,
            -15,
            -80,
            -49,
            -25,
            73,
            -12,
            21,
            -72,
            -105,
            -114,
            106,
            13,
            -89,
            16,
            23,
            -50,
            -98,
            -108,
            -69,
            -121,
            -38,
            21,
            -121,
            55,
            119,
            91,
            13,
            119,
            7,
            87,
            126,
            -79,
            73,
            -80,
            109,
            -81,
            -53,
            -77,
            113,
            -47,
            0,
            -120,
            36,
            -30,
            -109,
            102,
            87,
            -123,
            -45,
            60,
            -52,
            -76,
            84,
            119,
            112,
            -27,
            57,
            78,
            -69,
            115,
            -45,
            110,
            -7,
            -74,
            -52,
            111,
            -128,
            78,
            -33,
            34,
            33,
            -25,
            72,
            -34,
            -66,
            4,
            -101,
            -77,
            55,
            57,
            4,
            48,
            13,
            -64,
            48,
            16,
            106,
            -128,
            16,
            3,
            84,
            3,
            80,
            85,
            15,
            -14,
            -45,
            -115,
            70,
            -93,
            69,
            42,
            -112,
            44,
            89,
            -37,
            -28,
            16,
            -64,
            52,
            0,
            -61,
            64,
            -88,
            1,
            66,
            12,
            80,
            13,
            -80,
            -78,
            -122,
            -4,
            12,
            102,
            -30,
            125,
            49,
            -31,
            9,
            -42,
            96,
            -60,
            89,
            -65,
            -119,
            -110,
            24,
            97,
            58,
            -124,
            -107,
            -112,
            80,
            -121,
            -124,
            37,
            -124,
            -22,
            -112,
            -107,
            -57,
            -110,
            -79,
            -113,
            72,
            70,
            82,
            -92,
            41,
            -58,
            -41,
            57,
            0,
            94,
            19,
            46,
            -45,
            25,
            79,
            -32,
            -66,
            7,
            113,
            50,
            -113,
            -28,
            56,
            120,
            -96,
            -67,
            -63,
            -67,
            111,
            107,
            86,
            -78,
            -35,
            -15,
            23,
            101,
            111,
            125,
            109,
            118,
            -15,
            31,
            -62,
            57,
            127,
            -124,
            -112,
            35,
            -24,
            63,
            -97,
            119,
            -11,
            26,
            -52,
            -16,
            -101,
            -110,
            58,
            41,
            -38,
            -39,
            50,
            -17,
            52,
            -17,
            88,
            -21,
            114,
            -53,
            3,
            -71,
            -83,
            94,
            110,
            -103,
            -113,
            115,
            37,
            76,
            21,
            25,
            48,
            26,
            -32,
            -56,
            36,
            85,
            98,
            -63,
            104,
            -111,
            26,
            60,
            22,
            -84,
            -44,
            20,
            107,
            65,
            -34,
            -128,
            -47,
            -128,
            -88,
            10,
            -21,
            21,
            24,
            43,
            16,
            -103,
            36,
            -85,
            -60,
            84,
            -43,
            100,
            -36,
            55,
            59,
            125,
            52,
            -13,
            51,
            -118,
            -7,
            31,
            5,
            96,
            17,
            -9
        ],
        "style": {
            "fillGradientOffsetRatioX": 0,
            "markerSize": 2.4,
            "fillForeColor": {
                "red": 189,
                "green": 235,
                "blue": 255,
                "alpha": 255
            },
            "fillGradientOffsetRatioY": 0,
            "markerWidth": 0,
            "markerAngle": 0,
            "fillSymbolID": 0,
            "lineColor": {
                "red": 0,
                "green": 0,
                "blue": 0,
                "alpha": 255
            },
            "markerSymbolID": 0,
            "lineWidth": 0.1,
            "markerHeight": 0,
            "fillOpaqueRate": 100,
            "fillBackOpaque": true,
            "fillBackColor": {
                "red": 255,
                "green": 255,
                "blue": 255,
                "alpha": 255
            },
            "fillGradientMode": "NONE",
            "lineSymbolID": 0,
            "fillGradientAngle": 0
        },
        "prjCoordSys": null,
        "position": {
            "x": 117.0258845611524,
            "y": 40.96207518781254,
            "z": 2.7939677238464355E-7
        },
        "id": 4,
        "modelUrl": null,
        "partTopo": null
    },
    "fieldValues": [
        "4",
        "0",
        "[B@56ed8977",
        "",
        "模添加"
    ],
    "ID": 4
}]

        看到这儿大家也许很好奇这些参数信息是从哪里来的?难道要一个个手动书写吗?NO,并非如此。告诉您一个小秘密,小编这些参数是从点开一个对象Geometry数据,点击下图右侧的rjson得到的哦~只需要改相应的参数即可:
在这里插入图片描述在这里插入图片描述

3.更改要素:

        更改要素与添加要素参数区别是"fieldNames"、“fieldValues”、“geometry"三个信息参数中只需要"fieldNames”、"fieldValues"这两个参数即可。
在这里插入图片描述
        如三维点更新参数如下图所示,其他数据参数类似,这里就不做详细描述。

[{
    "ID": 7,
    "fieldNames": [
        "SMID",
        "SMUSERID",
        "SMGEOMETRY",
        "NAMEP"
    ],
    "fieldValues": [
        "7",
        "0",
        "",
        "点更新"
    ]
}]
4.删除要素:

在这里插入图片描述
        删除模式有两个“ID”和“SQL”,选“ID”时,[ ]里填写SMID值,如果删除多个,用“,”隔开即可,如[32,33,34]。选“SQL”时,feature删除要素必填里要写:SMID=32。
        以上是iServer里三维数据的增删改,那在WebGL里怎样用代码对接呢?下面来看WebGL通过对 features 资源执行 POST 请求完成对数据集中的要素进行添加、修改和删除操作思路与代码,本文小编就以三维点为例,先看一下WebGL数据更新显示效果:
在这里插入图片描述

1.GET请求获取数据构造实体

        通过GET请求获取isever发布的的数据服务,遍历到每个对象,获取每个对象的位置信息来构造点实体,获取每个对象的属性信息来构造文本实体。

var queryObj = {
					"getFeatureMode": "SQL",
					"datasetNames": ["属性更新:New_Point3D"],
					"maxFeatures": 1000,
					"queryParameter": {
						attributeFilter: "SMID >0 "
					}
				};
				var queryObjJSON = JSON.stringify(queryObj);
				console.log(queryObjJSON);
				$.ajax({
					type: 'GET',
					url: "http://localhost:8090/iserver/services/data---0--ShuXingGengXin/rest/data/featureResults/6579c49303dc43658915093e2132edf6_76b8f4a870e8403ca2b710140f3c0c24.rjson",
					data: queryObjJSON,
					success: function(data) {
						var resultObj = JSON.parse(data);
						console.log(resultObj);
						for(var i = 0; i < resultObj.featureUriList.length; i++) {
							console.log(resultObj.featureUriList.length);
							$.ajax({
								type: 'GET',
								url: resultObj.featureUriList[i] + ".rjson?hasGeometry=true",
								data: queryObjJSON,
								success: function(data) {
									var resultObj = JSON.parse(data);
									console.log(resultObj);

									a = viewer.entities.add({
										description: '三维点',
										name: '三维点',
										point: new Cesium.PointGraphics({
											color: new Cesium.Color(1, 1, 0),
											pixelSize: 10,
											outlineColor: new Cesium.Color(0, 1, 1),
											outlineWidth: 5
										}),
										position: Cesium.Cartesian3.fromDegrees(resultObj.geometry.x, resultObj.geometry.y, 10)
									});
									viewer.flyTo(a);
									b = viewer.entities.add({
										description: '三维点标签',
										name: '三维点标签',
										label: {
											text: resultObj.fieldValues[3],
											font: '18px Helvetica',
											fillColor: Cesium.Color.SKYBLUE,
											outlineColor: Cesium.Color.BLACK,
											outlineWidth: 4,
											style: Cesium.LabelStyle.FILL_AND_OUTLINE
										},
										position: Cesium.Cartesian3.fromDegrees(resultObj.geometry.x + 0.0010, resultObj.geometry.y + 0.0010, 100)
									});
								}
							});
						}

					}
				});
2.三维点要素添加

        对url: "http://localhost:8090/iserver/services/data—0–ShuXingGengXin/rest/data/datasources/%E5%B1%9E%E6%80%A7%E6%9B%B4%E6%96%B0/datasets/New_Point3D/features.rjson?returnContent=false"执行 POST 请求,在请求体中包含的参数见2里的三维点添加所示。

3.三维点要素更新

        对url: "http://localhost:8090/iserver/services/data—0–ShuXingGengXin/rest/data/datasources/%E5%B1%9E%E6%80%A7%E6%9B%B4%E6%96%B0/datasets/New_Point3D/features.rjson?_method=PUT"执行 POST 请求,在请求体中包含的参数见2里的三维点更新所示。对请求完生成的数据进行GET请求获取点位信息,在前端以实体方式进行渲染。

4.三维点要素删除

        对url: "http://localhost:8090/iserver/services/data—0–ShuXingGengXin/rest/data/datasources/%E5%B1%9E%E6%80%A7%E6%9B%B4%E6%96%B0/datasets/New_Point3D/features.rjson?_method=DELETE&deleteMode=SQL"执行 POST 请求,在请求体中包含的参数如下所示。对请求完生成的数据进行GET请求获取点位信息,在前端以实体方式进行渲染。

var NewFeature = {
						"attributeFilter": "SmID=33"
					};

URL中的参数如下:
在这里插入图片描述
本文详细代码请参见:https://download.csdn.net/download/supermapsupport/12011710

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值