* @function Turf.prototype.process * @description 执行 Turf.js 提供的相关空间分析方法。 * @param {string} type - Turf.js 提供的空间分析方法名。 * @param {Object} args - Turf.js 提供的空间分析方法对应的参数对象。 * @param {function} callback - 空间分析完成执行的回调函数,返回执行的结果。 * @param {boolean} addFeaturesToMap - 是否添加要素到地
(type, args, callback, addFeaturesToMap)
| 237 | * @param {boolean} addFeaturesToMap - 是否添加要素到地图。 |
| 238 | */ |
| 239 | process(type, args, callback, addFeaturesToMap) { |
| 240 | var result; |
| 241 | // 兼容版本4到5 |
| 242 | try{ |
| 243 | result = turf[type.split('.')[1]].apply(this, this.parse(type, args)); |
| 244 | }catch(e){ |
| 245 | result = turf[type.split('.')[1]].apply(this, this.parseOption(type, args)); |
| 246 | } |
| 247 | |
| 248 | var features = null; |
| 249 | try { |
| 250 | features = (new GeoJSON()).readFeatures(result); |
| 251 | } catch (e) { |
| 252 | if (callback) { |
| 253 | callback(result); |
| 254 | } |
| 255 | return; |
| 256 | } |
| 257 | addFeaturesToMap = addFeaturesToMap == null ? true : addFeaturesToMap; |
| 258 | if (addFeaturesToMap) { |
| 259 | this.addFeatures(features); |
| 260 | } |
| 261 | if (callback) { |
| 262 | callback(result); |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | parse(type, args) { |
| 267 | if (type === 'Transformation.union') { |
no test coverage detected