arcGis for javaScript4.x 简单实用的绘制点、线、面的geometry函数和symbol函数方法

1,使用new对象的默认的方法

const pointGeometry = new Point({
	longitude:-118.29026, 
	latitude:34.1816
});

const pointSymbol = new SimpleMarkerSymbol({
	color: [226, 119, 40],
	outline: {
		color: [255, 255, 255],
		width: 1
	}
})

线

const lineGeometry = new Polyline({
	paths: [
		[-118.29026, 34.1816],
		[-118.26451, 34.09664]
	]
});

const lineSymbol = new SimpleLineSymbol({
	color: [226, 119, 40],
	width: 2
});

var polygonGeometry = new Polygon({
	rings: [
		[-118.27653, 34.15121],
		[-118.2446, 34.15462],
		[-118.22915, 34.14439],
		[-118.23327, 34.12279],
		[-118.25318, 34.10972],
		[-118.26486, 34.11625],
		[-118.27653, 34.15121]
	]
});

var fillSymbol = new SimpleFillSymbol({
	color: [227, 139, 79, 0.8],
	outline: {
		color: [255, 255, 255],
		width: 1
	}
});

2,使用其它的方式

export default {
    methods: {
        createPointGeometry(longitude, latitude) {
            // 创建点 Geometry new Point()
            return {
                type: 'point',
                longitude,
                latitude
            }
        },
        createPointSymbol(color, style = 'circle', size, outlineColor, outlineWidth) {
            // 绘制点 Symbol
            return {
                type: "simple-marker",
                style,  // "circle"|"square"|"cross"|"x"|"diamond"|"triangle"|"path"
                color,
                size,
                outline: {
                    color: outlineColor,
                    width: outlineWidth
                }
            };
        },
        createPictureMarkerSymbol(url, width, height) {
            // 绘制点图标 Symbol
            return {
                type: "picture-marker",
                url, width, height
            };
        },
        createPolylineGeometry(paths) {
            // 创建线 Geometry new Polyline()
            return {
                type: 'polyline',
                paths
            }
        },
        createSimpleLineSymbol(color, width = 2, style = 'solid') {
            // 创建线 simpleLineSymbol
            return {
                type: 'simple-line', 
                color, width, 
                style // "dash"|"dash-dot"|"dot"|"long-dash"|"long-dash-dot"|
                	 // "long-dash-dot-dot"|"none"|"short-dash"|"short-dash-dot"
                	 // |"short-dash-dot-dot"|"short-dot"|"solid"
            }
        },
        createFillGeometry(rings = []) {
            // 创建图形 polygon new Polygon()
            return {
                type: 'polygon',
                rings
            }
        },
        createFillSymbol(color, style = 'solid', width, outlineColor) {
            // 绘制图形Symbol
            return {
                type: "simple-fill",    
                style,		// "backward-diagonal"|"cross"|"diagonal-cross"
                			//|"forward-diagonal"|"horizontal"|"none"|"solid"|"vertical"
                color,
                outline: {
                    color: outlineColor,
                    width
                }
            };
        },
        createToScreenGeometry(x, y) {
            // 创建 mapView.toScreen(geometry) 中的点geometry,用于屏幕定位
            return {
                x, y,
                spatialReference: {
                    wkid: 4326
                }
            }
        }
    }
}

ArcGIS JavaScript 4.x 中,击测距(Click-to-measure)是一种交互式功能,允许用户通过单击地图上的两来获取它们之间的距离。它通常集成在地图控制组件中,如`esri/dijit/MapNav`, 或者可以自定义事件处理程序来实现。 以下是基本步骤: 1. 导入必要的库:首先需要引入`esri/graphic``esri/symbol`用于创建图形,以及`esri/tasks/ MeasureTask`进行测量计算。 ```javascript import { Map, GraphicsLayer, Graphic, Symbol } from "esri/WebMap"; import { MeasureTask } from "esri/tasks/Measurement"; ``` 2. 创建地图并初始化测量任务: ```javascript const map = new Map({ // 地图配置... }); const measureTask = new MeasureTask({ url: "your-measurement-service-url" }); ``` 3. 绑定地图的click事件,并在事件处理函数中进行测距操作: ```javascript map.on("click", (event) => { if (!event.graphic) { // 如果击的是地图背景,创建一个新的图形 event.graphic = new Graphic(event.mapPoint); graphicsLayer.add(event.graphic); } // 更新第二个,如果存在 if (event.graphic.geometry.type === "Point") { const graphic2 = graphicsLayer.graphics.find((g) => g !== event.graphic); if (graphic2) { measureTask.execute({ geometry: [event.graphic.geometry, graphic2.geometry], outSR: map.spatialReference, }, (results) => { console.log(results.distance); // 显示结果或者更新UI }); } } }); // graphicsLayer用于存储临时绘制 const graphicsLayer = new GraphicsLayer(); map.addLayer(graphicsLayer); ``` 4. 结果处理:`measureTask.execute()` 返回一个测量结果对象,其中包含距离信息。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

mf_717714

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值