* @function WKTFormat.prototype.write * @description 将矢量要素或矢量要素数组序列化为 WKT 字符串。 * @param {(FeatureVector|Array)} features - 矢量要素或矢量要素数组。 * @returns {string} 表示几何的 WKT 字符串。
(features)
| 306 | * @returns {string} 表示几何的 WKT 字符串。 |
| 307 | */ |
| 308 | write(features) { |
| 309 | var collection, geometry, isCollection; |
| 310 | if (features.constructor === Array) { |
| 311 | collection = features; |
| 312 | isCollection = true; |
| 313 | } else { |
| 314 | collection = [features]; |
| 315 | isCollection = false; |
| 316 | } |
| 317 | var pieces = []; |
| 318 | if (isCollection) { |
| 319 | pieces.push('GEOMETRYCOLLECTION('); |
| 320 | } |
| 321 | for (var i = 0, len = collection.length; i < len; ++i) { |
| 322 | if (isCollection && i > 0) { |
| 323 | pieces.push(','); |
| 324 | } |
| 325 | geometry = collection[i].geometry; |
| 326 | pieces.push(this.extractGeometry(geometry)); |
| 327 | } |
| 328 | if (isCollection) { |
| 329 | pieces.push(')'); |
| 330 | } |
| 331 | return pieces.join(''); |
| 332 | } |
| 333 | |
| 334 | /** |
| 335 | * @function WKTFormat.prototype.extractGeometry |
no test coverage detected