Skip to content

Commit 2a37f2e

Browse files
author
caoxinke
committed
添加OL3地物编辑的例子和空间分析的Service。
1 parent fc73b25 commit 2a37f2e

File tree

4 files changed

+431
-0
lines changed

4 files changed

+431
-0
lines changed

build/deps.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,12 @@ var deps = {
166166
"./src/OL3/SuperMap/iServer/EditFeaturesService.js",
167167
"./src/OL3/SuperMap/iServer/GetGridCellInfosService.js"
168168
]
169+
},
170+
"SpatialAnalyst": {
171+
"name": "空间分析服务",
172+
"src": [
173+
"./src/OL3/SuperMap/iServer/SpatialAnalystService.js"
174+
]
169175
}
170176
},
171177
"Visual": {

examples/ol3/02_editFeatures.html

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
<!DOCTYPE>
2+
<html>
3+
<head>
4+
<title>地物编辑</title>
5+
<link rel="stylesheet" href="../css/bootstrap.min.css">
6+
<link rel="stylesheet" href="https://openlayers.org/en/v4.0.1/css/ol.css">
7+
<script type="text/javascript" src="https://openlayers.org/en/v4.0.1/build/ol-debug.js"></script>
8+
<script type="text/javascript" src="../../dist/SuperMapiClient9 for OL3.js"></script>
9+
<script type="text/javascript">
10+
var map, id, pointFeature, vectorSource, resultLayer,
11+
baseUrl = "http://support.supermap.com.cn:8090/iserver/services/map-world/rest/maps/World",
12+
urlCapital = "http://support.supermap.com.cn:8090/iserver/services/data-world/rest/data/datasources/World/datasets/Capitals",
13+
url = "http://support.supermap.com.cn:8090/iserver/services/data-world/rest/data";
14+
function init() {
15+
map = new ol.Map({
16+
target: 'map',
17+
view: new ol.View({
18+
center: [110, 30],
19+
zoom: 3,
20+
projection: 'EPSG:4326'
21+
})
22+
});
23+
map.addLayer(new ol.supermap.TiledMapLayer(baseUrl, {"pro": "4326"}));
24+
initFeature();
25+
}
26+
27+
function initFeature() {
28+
var polygon = new ol.geom.Polygon([[[118, 20], [120, 20], [120, 50], [-120, 50], [118, 20]]]);
29+
var getFeaturesService = new ol.supermap.GetFeaturesService(url);
30+
getFeaturesService.on("complete", function (serviceResult) {
31+
var features = (new ol.format.GeoJSON()).readFeatures(serviceResult.element.result);
32+
for (var i = 0; i < features.length; i++) {
33+
features[i].setStyle(new ol.style.Style({
34+
image: new ol.style.Icon(({
35+
src: 'http://support.supermap.com.cn:8090/iserver/iClient/forJavaScript/examples/images/markerbig_select.png'
36+
}))
37+
}));
38+
}
39+
vectorSource = new ol.source.Vector({
40+
features: features
41+
})
42+
resultLayer = new ol.layer.Vector({
43+
source: vectorSource,
44+
});
45+
map.addLayer(resultLayer);
46+
});
47+
getFeaturesService.getFeaturesByGeometry({
48+
datasetNames: ["World:Capitals"],
49+
geometry: polygon,
50+
spatialQueryMode: "INTERSECT"
51+
});
52+
}
53+
54+
function addMarker() {
55+
if (pointFeature) {
56+
vectorSource.removeFeature(pointFeature);
57+
}
58+
var xmax = 120, xmin = 100, ymax = 50, ymin = 20;
59+
pointFeature = new ol.Feature(new ol.geom.Point([Math.floor(Math.random() * (xmax - xmin + 1) + xmin), Math.floor(Math.random() * (ymax - ymin + 1) + ymin)]));
60+
pointFeature.setStyle(new ol.style.Style({
61+
image: new ol.style.Icon(({
62+
src: 'http://support.supermap.com.cn:8090/iserver/iClient/forJavaScript/examples/images/markerbig.png'
63+
}))
64+
}));
65+
vectorSource.addFeature(pointFeature);
66+
}
67+
68+
function commit() {
69+
var me = this;
70+
var editFeaturesService = new ol.supermap.EditFeaturesService(urlCapital);
71+
editFeaturesService.editFeatures({
72+
features: pointFeature.getGeometry(),
73+
editType: "add",
74+
returnContent: true
75+
});
76+
editFeaturesService.on("complete", function (serviceResult) {
77+
if (serviceResult.element.result.succeed) {
78+
id = serviceResult.element.result[0];
79+
map.removeLayer(resultLayer);
80+
me.initFeature();
81+
}
82+
});
83+
}
84+
function clearLayer() {
85+
var me = this;
86+
var editFeaturesService = new ol.supermap.EditFeaturesService(urlCapital);
87+
editFeaturesService.editFeatures({
88+
IDs: [id],
89+
editType: "delete"
90+
});
91+
editFeaturesService.on("complete", function (serviceResult) {
92+
if (serviceResult.element.result.succeed) {
93+
map.removeLayer(resultLayer);
94+
pointFeature = null;
95+
me.initFeature();
96+
} else {
97+
alert("删除失败")
98+
}
99+
});
100+
}
101+
</script>
102+
</head>
103+
<body onload="init()" onbeforeunload="closeLayer()" style=" margin: 0;overflow: hidden;background: #fff;">
104+
<div id="toolbar" style=" position: relative;padding-top: 10px; padding-bottom: 10px;">
105+
<input type="button" class="btn btn-primary" value="添加地物" onclick="addMarker()"/>
106+
<input type="button" class="btn btn-primary" value="提交添加" onclick="commit()"/>
107+
<input type="button" class="btn btn-primary" value="清除结果" onclick="clearLayer()"/>
108+
</div>
109+
<div id="map" style="margin:0 auto;position: relative; height: 510px;border: 1px solid #3473b7;"></div>
110+
</body>
111+
</html>

examples/ol3/03_BufferAnalyst.html

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>数据集栅格查询</title>
6+
<link rel="stylesheet" href="../css/bootstrap.min.css">
7+
<link rel="stylesheet" href="../../dist/SuperMapiClient9 for OL3.css">
8+
<script type="text/javascript" src="../../dist/SuperMapiClient9 for OL3.js"></script>
9+
<script type="text/javascript">
10+
11+
function init() {
12+
13+
}
14+
15+
function bufferAnalyst() {
16+
}
17+
18+
function clearLayer() {
19+
}
20+
21+
</script>
22+
</head>
23+
<body onload="init()" style=" margin: 0;overflow: hidden;background: #fff;">
24+
<div id="toolbar" style=" position: relative;padding-top: 10px; padding-bottom: 10px;">
25+
<input type="button" class="btn btn-primary" value="缓冲区分析" onclick="bufferAnalyst()"/>
26+
<input type="button" class="btn btn-primary" value="清除结果" onclick="clearLayer()"/>
27+
</div>
28+
<div id="map" style="margin:0 auto;position: relative; height: 510px;border: 1px solid #3473b7;"></div>
29+
</body>
30+
</html>

0 commit comments

Comments
 (0)