import { GLOBALCONFIG } from '@/config'; import { loadModules } from 'esri-loader'; type MapModules1 = [typeof import('esri/tasks/QueryTask'), typeof import('esri/tasks/query'), typeof import('esri/graphic'), typeof import('esri/symbols/SimpleFillSymbol'), typeof import('esri/tasks/GeometryService'), typeof import('esri/geometry/Polygon'), typeof import('esri/tasks/AreasAndLengthsParameters'), typeof import('esri/symbols/SimpleLineSymbol'), typeof import('esri/Color')]; interface Options { url: string; map: import('esri/map'); layerIds: number[]; geometry?: any; } export const query = async (options: Options) => { return new Promise(async (resolve, reject) => { try { const { url, map, layerIds, geometry } = options; const mapRes = await loadModules(['esri/tasks/QueryTask', 'esri/tasks/query', 'esri/graphic', 'esri/symbols/SimpleFillSymbol', 'esri/tasks/GeometryService', 'esri/geometry/Polygon', 'esri/tasks/AreasAndLengthsParameters', 'esri/symbols/SimpleLineSymbol', 'esri/Color'], { url: `${GLOBALCONFIG.BASEGIS.APIHOST}/dojo/dojo.js` }); const [QueryTask, Query, Graphic, SimpleFillSymbol, GeometryService, Polygon, AreasAndLengthsParameters, SimpleLineSymbol, Color] = mapRes as MapModules1; const urls = window.lv.url + '/' + window.lv.layerIds[0]; const queryTask = new QueryTask(urls); const query = new Query(); //空间查询的几何对象 query.geometry = geometry; //服务器给我们返回的字段信息,*代表返回所有字段 query.outFields = ['*']; //空间参考信息 query.outSpatialReference = map.spatialReference; //query.outSpatialReference = _this.props.mapControl.map.spatialReference; //查询的标准,此处代表和geometry相交的图形都要返回 query.spatialRelationship = Query.SPATIAL_REL_INTERSECTS; //是否返回几何信息 query.returnGeometry = true; const result1 = await queryTask.execute(query); if (result1 && result1.features.length === 0) { resolve(0); return; } const geometryService = new GeometryService(GLOBALCONFIG.BASEGIS.GEOMETRYSERVICE); const geometries = result1.features.map((item: any) => item.geometry); const result = await geometryService.intersect(geometries, geometry); const uniRes = await geometryService.union(result); const areaRes: any = await distancePolygon(map, uniRes); const symbol1 = new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID, new SimpleLineSymbol(SimpleLineSymbol.STYLE_DASHDOT, new Color([255, 0, 0, 0.8]), 2), new Color([255, 0, 0, 0.8])); var graphic = new Graphic(uniRes, symbol1); //_this.props.mapControl.map.graphics.add(graphic); map.graphics.add(graphic); if (areaRes && areaRes.result && areaRes.result.areas) { resolve(Number(areaRes.result.areas)); } else { reject(0); } resolve(result1); } catch (e) { reject(e); } }); }; export const distancePolygon = async (map: any, geometry: any) => { return new Promise(async (resolve, reject) => { const result = await loadModules(['esri/tasks/GeometryService', 'esri/tasks/AreasAndLengthsParameters'], { url: `${GLOBALCONFIG.BASEGIS.APIHOST}/dojo/dojo.js` }); const [GeometryService, AreasAndLengthsParameters] = result; let geometryService = new GeometryService(GLOBALCONFIG.BASEGIS.GEOMETRYSERVICE); const areasAndLengthParams = new AreasAndLengthsParameters(); areasAndLengthParams.lengthUnit = GeometryService.UNIT_FOOT; areasAndLengthParams.areaUnit = GeometryService.UNIT_SQUARE_METERS; areasAndLengthParams.calculationType = 'preserveShape'; geometryService.simplify([geometry], function (simplifiedGeometries: any) { areasAndLengthParams.polygons = simplifiedGeometries; geometryService.areasAndLengths(areasAndLengthParams); }); geometryService.on('areas-and-lengths-complete', (d: any) => { resolve(d); }); }); };
正文
arcgis api 查询裁剪
文章版权声明:除非注明,否则均为
譬如朝露_策温技术开发工作室博客原创文章,转载或复制请以超链接形式并注明出处。
发表评论
侧栏公告
寄语
譬如朝露博客是一个分享前端知识的网站,联系方式11523518。
热评文章
标签列表
热门文章
友情链接