ArcGIS API for JavaScript 缓冲区分析、河涌关联分析、集中连片分析

1、ArcGIS API for JavaScript 实现缓冲区分析、河涌关联分析、集中连片分析。

2、场景需求:查询缓冲区域范围的鱼塘;查询某条河涌关联的鱼塘;鱼塘的集中连片性。

3、vue页面实现代码示例:

javascript 复制代码
<template>
   <div/>
</template>
<script>
import * as geometryEngine from '@arcgis/core/geometry/geometryEngine.js'
import Graphic from '@arcgis/core/Graphic'
export default {
	props: {
        mapAndView: {
            type: Object,
            default: () => {
                return {}
            }
        }
    },
    data() {
        return {
            
        }
    },
    computed: {
        ...mapState({
            highlight: state => state.map.highlight,
            distance: state => state.aquaculture.distance,
            buffer: state => state.aquaculture.spatialAnalyse.buffer,
            riverRelated: state => state.aquaculture.spatialAnalyse.riverRelated,
            continuous: state => state.aquaculture.spatialAnalyse.continuous
        })
    },
	mounted() {
        this.addMapClickEventListener()
    },
	methods: {
		 addMapClickEventListener() {
            const clickHandler = this.mapAndView.on('click', event => {
                this.mapAndView.hitTest(event).then(async res => {
                    if (!res.results.length) {
                        return
                    }
                    let graphic = res.results[0].graphic
                    //缓冲区分析
                    if (this.buffer) {
                        this.goAndHighlight(graphic)
                        this.doBuffer(graphic.geometry, this.distance)
                    }
                    //河涌关联分析
                    if (this.riverRelated && graphic.layer.id === 'riverLayer') {
                        this.goAndHighlight(graphic)
                        this.doRiverRelated(graphic.geometry, this.distance)
                    }
                    //养殖场、鱼塘集中连片分析
                    if (this.continuous && (graphic.layer.id === 'aquacultureLayer' || graphic.layer.id === 'pondLayer')) {
                        this.mapAndView.graphics.removeAll()
                        this.doCentrallyContinuous(graphic.geometry, 20, graphic.layer.id)
                    }
                })
            })

            this.$once('hook:beforeDestroy', () => {
                if (clickHandler) {
                    clickHandler.remove()
                }
            })
        },
        //高亮与定位
        goAndHighlight(graphic) {
            this.mapAndView.whenLayerView(graphic.layer).then(layerView => {
                if (this.highlight) {
                    this.highlight.remove()
                }
                this.$store.commit('map/setHighlight', layerView.highlight(graphic))
                this.mapAndView.goTo({ target: graphic })
            })
        },
        // 空间几何图形查询
		queryFeaturesByGeometry(mapView, layerId, geometry, relationship) {
		    if (!mapView?.map) {
		        return
		    }
		    const queryLayer = mapView.map.findLayerById(layerId)
		    if (!queryLayer) {
		        return
		    }
		    return queryLayer.queryFeatures({
		        geometry: geometry, // 绘制的范围(点、线、面等几何图形)
		        outFields: ['*'], // 返回的字段
		        returnGeometry: true, // 是否返回geometry
		        spatialRelationship: relationship || 'intersects', // // 空间关系:相交、包含等
		        where: '' // 其它查询条件,格式参考sql语句,例如status = 1;
		    }).then(res => {
		        if (res.features.length) {
		            return res.features
		        }
		    })
		 },
		 // 缓冲区分析  distance:缓冲区距离(数值类型)
		 async doBuffer(geometry, distance) {
		     // 根据距离获取缓冲区域图形
		     const bufferGeometry = geometryEngine.geodesicBuffer(geometry, distance, 'meters')// 缓冲区
		     //缓冲区域添加在地图上的渲染效果
		     let symbol = {
		         type: 'simple-fill',
		         color: 'rgba(255,0,255,0.3)',
		         outline: {
		             color: '#F0DB6F',
		             style: 'dot',
		             width: 1
		         }
		     }
		     let graphic = new Graphic({ 
		         geometry: bufferGeometry,
		         symbol: symbol 
		     })
			 this.mapAndView.graphics.removeAll()
		     this.mapAndView.graphics.add(graphic)
		     // 空间查询缓冲区范围内的鱼塘
		     fishPondFeatures = await this.queryFeaturesByGeometry(this.mapAndView, 'pondLayer', bufferGeometry)
		     console.log('缓冲区范围的鱼塘:',  fishPondFeatures)
		     //地图渲染鱼塘
		     this.renderGraphics(fishPondFeatures)
		 },
		 // 河涌关联分析(空间位置距离关联)  distance:缓冲区距离(数值类型)
        async doRiverRelated(geometry, distance) {
        	// 根据距离获取缓冲区域图形
        	const bufferGeometry = geometryEngine.geodesicBuffer(geometry, distance, 'meters')// 缓冲区
        	//缓冲区域添加在地图上的渲染效果
            let symbol = {
                type: 'simple-fill',
                color: 'rgba(0,255,0,0.3)',
                outline: {
                    color: '#F0DB6F',
                    style: 'dot',
                    width: 1
                }
            }
            let graphic = new Graphic({ 
                geometry: bufferGeometry,
                symbol: symbol 
            })

             this.mapAndView.graphics.removeAll()
		     this.mapAndView.graphics.add(graphic)
		     // 空间查询缓冲区范围内的鱼塘(河涌关联的鱼塘)
		     fishPondFeatures = await this.queryFeaturesByGeometry(this.mapAndView, 'pondLayer', bufferGeometry)
		     console.log('河涌关联的鱼塘:',  fishPondFeatures)
		      //地图渲染鱼塘
		     this.renderGraphics(fishPondFeatures)
        },
        // 养殖场、鱼塘的集中连片分析  distance:聚合距离(数值类型)
        async doCentrallyContinuous(geometry, distance, layerId) {
            // 聚合图形(缓冲区图形)
            // 第一次缓冲区查询
            let bufferGeometry = geometryEngine.geodesicBuffer(geometry, distance, 'meters')
            let features = await this.queryFeaturesByGeometry(this.mapAndView, layerId, bufferGeometry)
             // 第二次缓冲区查询( 第一次查询结果构建目标参数)
            let tempRings = []
            features.map(item => {
                tempRings.push(item.geometry.rings[0])
            })
            geometry.rings = tempRings
            bufferGeometry = geometryEngine.geodesicBuffer(geometry, distance, 'meters')
            let secondFeatures = await this.queryFeaturesByGeometry(this.mapAndView, layerId, bufferGeometry)
            // 多次缓冲查询,直到最后查询到的图形list数据相同为止
            if (JSON.stringify(secondFeatures) === JSON.stringify(features)) {
                //地图渲染集中连片区域
                let features = this.renderGraphics(secondFeatures)
            } else {
                //递归查询
                this.doCentrallyContinuous(geometry, distance, layerId)
            }
        },
        // 渲染集中连片区域
        renderGraphics(features) {
            let symbol = {
                type: 'simple-fill',
                color: 'rgba(255,0,255,0.3)',
                outline: {
                    color: '#F0DB6F',
                    width: 1
                }
            }
            let graphics = []
            features.map(item => {
                let graphic = new Graphic({ 
                    geometry: item.geometry,
                    attributes: item.attributes,
                    symbol: symbol 
                })
                graphics.push(graphic)
            })
            this.mapAndView.graphics.addMany(graphics)
            return features
        },
	}
}
</script>
相关推荐
不可能的是24 分钟前
Claude Code 子 Agent 机制全解:怎么跑起来、怎么被管理、怎么互不干扰
javascript
HSunR1 小时前
dify 搭建ai作业批改流
开发语言·前端·javascript
代码不加糖1 小时前
2026 跨境电商独立站实战:从 0 到 1 搭建高转化 SaaS 商城(附源码)
开发语言·前端·javascript
用户617517157013 小时前
关于普通函数和箭头函数的this
javascript
RPGMZ3 小时前
RPGMakerMZ 地图存档点制作 标题继续游戏直接读取存档
开发语言·javascript·游戏·游戏引擎·rpgmz·rpgmakermz
有一个好名字4 小时前
Agent Loop —— 一切从那个 while 循环开始
前端·javascript·chrome
EF@蛐蛐堂4 小时前
【js】浏览器滚动条优化组件OverlayScrollbars
开发语言·javascript·ecmascript
辰同学ovo5 小时前
从全局登录状态管理学习 Redux
前端·javascript·学习·react.js
爱看书的小沐5 小时前
【小沐杂货铺】基于Three.js绘制三维艺术画廊3DArtGallery (Three.js,WebGL)
javascript·3d·webgl·three.js·babylon.js·三维画廊
ZC跨境爬虫5 小时前
跟着 MDN 学 HTML day_12:(HTML网页图片嵌入)
前端·javascript·css·ui·html