参考

http://support.supermap.com.cn:8090/iserver/iClient/forJavaScript/examples/classic/editor.html#query_getFeatureBySQL

API

https://iclient.supermap.io/web/libs/iclient8c/apidoc/files/SuperMap/REST/Data/GetFeaturesBySQLService-js.html

https://iclient.supermap.io/web/libs/iclient8c/apidoc/files/SuperMap/REST/Data/GetFeaturesServiceBase-js.html#SuperMap.REST.GetFeaturesServiceBase

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<!--********************************************************************
* Copyright© 2000 - 2021 SuperMap Software Co.Ltd. All rights reserved.
*********************************************************************-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title data-i18n="resources.title_getFeatureBySQL"></title>
<style type="text/css">
body {
margin: 0;
overflow: hidden;
background: #fff;
width: 100%;
height: 100%
}

#map {
position: absolute;
width: 100%;
height: 100%;
}

#toolbar {
position: absolute;
top: 50px;
right: 10px;
text-align: center;
z-index: 100;
border-radius: 4px;
}
</style>
</head>
<body>
<div id="toolbar" class="panel panel-primary">
<div class='panel-heading'>
<h5 class='panel-title text-center' data-i18n="resources.title_getFeatureBySQL"></h5></div>
<div class='panel-body content'>
<input type="button" class="btn btn-default" data-i18n="[value]resources.text_query" onclick="getFeaturesBySQL()"/>&nbsp;
<input type="button" class="btn btn-default" data-i18n="[value]resources.text_input_value_clear" onclick="clearFeatures()"/>
</div>
</div>
<div id="map"></div>
<script type="text/javascript" include="bootstrap,widgets.alert" src="../js/include-web.js"></script>
<script type="text/javascript" exclude="iclient-classic" src="../../dist/classic/include-classic.js"></script>
<script>
var host = window.isLocal ? window.server : "https://iserver.supermap.io";
var map, local, layer, vectorLayer,
style = {
strokeColor: "#304DBE",
strokeWidth: 1,
fillColor: "#304DBE",
fillOpacity: "0.8"
},
url1 = host + "/iserver/services/map-world/rest/maps/World",
url2 = host + "/iserver/services/data-world/rest/data";

init();

function init() {
map = new SuperMap.Map("map", {
controls: [
new SuperMap.Control.ScaleLine(),
new SuperMap.Control.Zoom(),
new SuperMap.Control.Navigation({
dragPanOptions: {
enableKinetic: true
}
})]
});
map.addControl(new SuperMap.Control.LayerSwitcher(), new SuperMap.Pixel(42, 80));
layer = new SuperMap.Layer.TiledDynamicRESTLayer("World", url1, {
transparent: true,
cacheEnabled: true
}, {maxResolution: "auto"});
layer.events.on({"layerInitialized": addLayer});
vectorLayer = new SuperMap.Layer.Vector("Vector Layer");
}

function addLayer() {
map.addLayers([layer, vectorLayer]);
map.setCenter(new SuperMap.LonLat(0, 0), 0);
}

function getFeaturesBySQL() {
vectorLayer.removeAllFeatures();

var getFeatureParam, getFeatureBySQLService, getFeatureBySQLParams;

getFeatureParam = new SuperMap.REST.FilterParameter({
name: "Countries@World",
attributeFilter: "SMID = 247"
});
getFeatureBySQLParams = new SuperMap.REST.GetFeaturesBySQLParameters({
queryParameter: getFeatureParam,
datasetNames: ["World:Countries"]
});
getFeatureBySQLService = new SuperMap.REST.GetFeaturesBySQLService(url2, {
eventListeners: {"processCompleted": processCompleted, "processFailed": processFailed}
});

getFeatureBySQLService.processAsync(getFeatureBySQLParams);
}

function processCompleted(getFeaturesEventArgs) {
var i, len, features, feature, result = getFeaturesEventArgs.result;
if (result && result.features) {
features = result.features
for (i = 0, len = features.length; i < len; i++) {
feature = features[i];
feature.style = style;
vectorLayer.addFeatures(feature);
}
}
}

function processFailed(e) {
widgets.alert.showAlert(e.error.errorMsg, false);
}

function clearFeatures() {
//先清除上次的显示结果
vectorLayer.removeAllFeatures();
vectorLayer.refresh();
}

</script>

</body>
</html>