//假设获取的图形对象名为f
var componets = f.geometry.components[0].components
var changedComponents = _.map(componets, function(c) {
return new OpenLayers.Geometry.Point(c.x, c.y)
f.geometry.components[0].components = changedComponents
var tuxingObj = f.geometry.components[0]
// 1. 获取图层
var layer = map.getLayersByName(layerName)
//2. 遍历比较图形包含点
_.each(layer.features, function(feature) {
if (tuxingObj.containsPoint(feature.geometry)) {
console.log(feature)
//假设获取的图形对象名为f var componets = f.geometry.components[0].components; var changedComponents = _.map(componets, function(c) { return new OpenLayers.Geometry.Point(c.x, c.y); });f.geometry.compo
testLat,testLon,polygonPoints分别是要判断的点的纬度坐标、点的经度坐标、多边形的顶点数组
注:openlayers获取多边形的顶点坐标数组时,最后一个点的坐标与起始点坐标相同,记得将最后一个点的坐标排除出去
function IsPointInPolygon(testLat,testLon,polygonPoints){
if (polygonPoints.length < 3) return false;
let iSum = 0,iCount =
在opanlayers4官方API已经有一个方法:intersectsCoordinate(coordinate),用于判断一个点coordinate是否在闭合图形的内部,返回值为布尔类型的,true表示点在多边形的内部,false表示点不在多边形的内部。
详细代码如下所示:
var geo = feature.getGeometry();//feture是几何元素
var isIn = ...
需要先转成polygon。
let _points = JSON.parse(that.hotZone).coordinates
this.polygonFeature = new Feature({
geometry: new Polygon(_points)
然后在点击map的singleclick里面
let geo = that.pol...
如图所示,如何取出用OpenLayers.Control.DrawFeature画出来多边形所包围那个点而不被其他点干扰。
JS代码(写在画图工具的featureAdded(f)方法内):
var components = f.geometry.components,//f为OpenLayers_Feature_Vector类型的对象
bottom = f.geometry.bo
1、 使用truf库的booleanContains函数,这个函数可以检测两个几何是否为包容关系
使用:引入相关函数,因为truf识别的geometry不是openlayers中的geometry,所以需要使用其提供的函数,转换成对应的geometry
import booleanContains from '@turf/boolean-contains'
import {geometry, po...
```javascript
var draw = new ol.interaction.Draw({
type: 'Point', // 或 'LineString', 'Polygon', 'Circle' 等
5. 添加绘制工具到地图:将绘制工具添加到地图的交互列表中。
```javascript
map.addInteraction(draw);
6. 处理绘制完成事件:在绘制完成后,获取绘制的几何对象并进行相应操作。
```javascript
draw.on('drawend', function(event) {
var feature = event.feature;
// 在这里可以对绘制的几何对象进行进一步的处理
以上是一个基本的 OpenLayers 绘制图形的流程。你可以根据自己的需求进行进一步的定制和扩展。希望对你有所帮助!