针对查询
- 调用
-
let rule = {
-
name: "用途",
-
value: "私宅"
-
};
-
let polygon = cw5.geometryCreator.createPolygon([[150139, 37917, 64],
-
[150180, 37854, 64], [150258, 37887, 64],
-
[150139, 37917, 64]]);
-
cw5.highLightUtils.unHighlightAll();
-
switch (index) {
-
case 1:
-
let res = cw5.queryUtils.queryByField("buildingbuilding");
-
let fids=[];
-
for(let i=0;i<res.features.length;i++){
-
fids.push(res.features[i].oid)
-
}
-
cw5.highLightUtils.multiple(res.fc,fids) //高亮若干要素
-
break;
-
case 2:
-
let count = cw5.queryUtils.queryCount("buildingbaimo", rule);
-
alert("图层要素总数查询成功,共" + count + "条");
-
break;
-
case 3:
-
let res2 = cw5.queryUtils.queryByGeometry("buildingbuilding",polygon);
-
let fids2=[];
-
for(let i=0;i<res2.features.length;i++){
-
fids2.push(res2.features[i].oid)
-
}
-
cw5.highLightUtils.multiple(res2.fc,fids2) //高亮若干要素
-
break;
-
}
- 查询 queryUtils工具
```javascript
import { cw5 } from "../index.js";
export const queryUtils = {};
/**
-
属性字段查询结果
-
handle 查询图层名称
-
rule 查询条件 name:字段名称 value:对应值
-
*/
queryUtils.queryByField = function(handle,rule) {
if(handle==null){
alert("查询图层名称不能为空")
}
let fc = cw5.sceneLayerCtrl.getFc(handle);
if(fc==null){
alert("未找到该图层")
}
let filter = cw5.__g.new_QueryFilter;
filter.resultLimit=1000;
if(rule==null){
filter.whereClause =""
}
else {
filter.whereClause = rule.name + "='" + rule.value + "'";
}let cursor = fc.search(filter, true); //查询指定的图层 返回游标 数据库游标
let fdeRow = null;
if (cursor != null || cursor != -1) {
let featureSet = {
handle:handle,
fc:fc,
features:[]
};
let count = 0;
while ((fdeRow = cursor.nextRow()) != null) {
count++;
var fields = fdeRow.fields;
var fCount = fields.count;
let obj = {};
for (var i = 0; i < fCount; i++) {
let fieldsName = fields.get(i).name;
let fieldsValue = fdeRow.getValue(i);
if(fieldsName=="Geometry"){
fieldsValue=cw5.geometryCreator.createGeometry(fieldsValue)
}
obj[fieldsName] = fieldsValue;
}
featureSet.features.push(obj);
}
cursor.close();
return featureSet;