> **本文回答**：`svc.conditionQueryFeature` / `pointQueryFeature` / `rectQueryFeature` 的用法、字段表、常见 SQL（**速查版**）。
>
> **完整文档** ⇒ [query-features](query-features.md)（包含全部 36 个 `name='xx'` 类型、s3/s4/s5/n5~n10 在每种实体下的字段含义、详细 SQL 示例、绘制姿势）。本文只是 API 速查。

## 一、前置条件

几何渲染方式打开的图才有空间数据库可查：

```js
await svc.openMap({ mapid, mapopenway: vjmap.MapOpenWay.GeomRender });
```

内存模式无法用 SQL；改用 [query-expression](query-expression.md)。

## 二、表结构（只写 `where` 后面部分）

| 字段 | 类型 | 说明 |
|---|---|---|
| `id` | int | 自增 ID |
| `objectid` | text | 实体 ID（块/组/表格有特殊命名规则，详见 [query-features 第二节](query-features.md#二后台数据库表结构)） |
| `layerindex` | int | 图层索引 |
| `name` | text | 实体类型值（**字符串**），如 `'1'` = AcDbLine。完整 36 类见 [query-features 第三节](query-features.md#三所有实体类型-namexx-完整列表) |
| `color` | int | 颜色（RGB + Alpha，多为负数） |
| `s1..s5` | text | 字符型属性。`s1`=线型；`s2`=扩展字典；`s3..s5` 含义随类型变化 |
| `n1..n10` | float | 数值型属性。`n1`=颜色索引；`n2`=线型比例；`n3`=线宽；`n4`=透明度；`n5..n10` 含义随类型变化 |
| `geom` | GEOMETRY | 实体外包矩形（用于空间查询） |

> ⚠️ `s3..s5` / `n5..n10` 的具体含义**因实体类型而异**（圆的 `n7=radius`，直线的 `n6=length`...）。完整对照见 [query-features 第四节](query-features.md#四字段含义随类型变化s3s4s5n5n10)。

## 三、条件查询 `conditionQueryFeature`

```js
const res = await svc.conditionQueryFeature({
  condition: `name='13' or name='12'`,   // SQL where 部分
  fields: "objectid,text,envelop",        // 要返回的字段
  geom: true,                              // 走几何渲染空间库（不是"返回几何"；缺省取当前图打开方式）
  limit: 100000,                           // 默认 100，需显式放大
  bounds: [x1,y1,x2,y2],                   // 可选：矩形或点数组（多边形）
  isContains: false,                       // 范围查询时：false=相交/true=包含
  includegeom: true, realgeom: true        // 要真实 geojson：两者同传（只传 realgeom 无效），且 fields 须含 geojson；数量少时用
});
// res.recordCount, res.result[]
```

### 分页

```js
let begin = 0, all = [];
while (true) {
  const q = await svc.conditionQueryFeature({ condition, fields, limit: 10000, beginpos: begin });
  all.push(...(q.result || []));
  begin += q.result.length;
  if (all.length >= q.recordCount) break;
}
```

### 常用 SQL 示例（更多见 [query-features 第五节](query-features.md#五sql-条件示例按场景分类)）

```text
name='1'                              // 所有直线
name='4' and layerindex=0            // 0 图层的三维多段线
name='13' and color=-16776961         // 红色单行文字（0xFF0000FF）
objectid='9BE'                        // 指定 objectid
name='13' or name='12' or name='26' or name='27'
                                      // 所有文字（单行/多行/属性注记/块属性）
objectid like 'EA_%'                  // 指定块下的子实体
name='1' and n6 = 10                  // 长度 10 的直线（n6=length）
name='7' and n7 = 5                   // 半径 5 的圆（n7=radius）
name='10' and s5='门'                  // 块名为"门"的所有块参照（s5=blockname）
name='13' and s4 like 'DZ%'           // 文字内容以 DZ 开头（s4=text）
name='2' and n6=1                     // 闭合的多段线（n6=isclosed）
```

## 四、点查询 `pointQueryFeature`

```js
const q = await svc.pointQueryFeature({
  x: 3200, y: 1800,
  pixelsize: 5,
  condition: `name='7'`,               // 可选进一步过滤
  zoom: map.getZoom(),                 // 用于 pixel→几何长度
  limit: 20,
  geom: true,
  toMapCoordinate: true                // 直接返回 CAD 坐标
});
```

典型场景：**鼠标点击选实体**。

## 五、矩形 / 多边形查询 `rectQueryFeature`

```js
// 矩形
await svc.rectQueryFeature({
  x1, y1, x2, y2,
  condition: `name='7'`,
  limit: 100000,
  geom: true
});

// 多边形：用 conditionQueryFeature + bounds 数组
await svc.conditionQueryFeature({
  condition: "name='7'",
  bounds: [[p1x,p1y],[p2x,p2y],[p3x,p3y],[p4x,p4y]],
  isContains: true
});
```

## 六、把查询结果绘制到地图

```js
const polygons = q.result.map(r => {
  const bounds = map.getEnvelopBounds(r.envelop);
  return {
    points: map.toLngLat(bounds.toPointArray()),
    properties: {
      name: r.objectid,
      color: vjmap.entColorToHtmlColor(r.color),
      text: r.text
    }
  };
});
const layer = new vjmap.Polygon({
  data: polygons,
  fillColor: ["get", "color"],
  fillOpacity: 0.4,
  fillOutlineColor: "#fff"
});
layer.addTo(map);
```

## 七、查询返回字段速查

常用：`objectid` / `bounds` / `envelop` / `points` / `center` / `radius` / `text` / `contents` / `blockname` / `area` / `length`。

完整字段表与各类型字段对照见 [query-features 第八节](query-features.md#八查询返回结果字段)。

## 八、常见坑

1. **`name=1` 写成不带引号** → `name` 是字符串字段，必须 `name='1'`。
2. **没传 `limit`** → 默认只给 100 条（点查询只给 1 条），业务上误判为"查不全"。
3. **`realgeom: true` 但数量巨大** → 流量爆炸。建议仅在单条详情时使用。
4. **`isContains: true` 遗漏实体**：矩形包含很严格，轻微溢出就不算包含。通常 `false`（相交）更符合直觉。
5. **拼 SQL 时用户输入没转义** → 注入风险。SDK 没内置防护，要么自己转义，要么只允许白名单字段。

更多坑见 [query-features 第十二节](query-features.md#十二常见坑)。

## 九、相关参考

- **完整查询文档** ⇒ [query-features](query-features.md)（实体类型表、字段含义、详细 SQL）
- 表达式查询（内存模式 / 复杂逻辑）⇒ [query-expression](query-expression.md)
- 综合用例（自动分图 / 提表 / 中心线）⇒ [query-cases](query-cases.md)
- 全文搜索 ⇒ [query-fulltext](query-fulltext.md)
- 服务端样式过滤 ⇒ [svr-style-var](svr-style-var.md)
