openlayers判断点击的经纬度坐标是否在图层中

点击地图或者鼠标在地图上面滑动时所经过的坐标是否在否个图层上

map.on('pointermove', function (e) {
            isLocationArr = new Array();
                // 转换为web merctor投影
                var destinationPro = "EPSG:3857";
                // 地理原始投影
                var sourcePro = 'EPSG:4326';
                var featureCoords = ol.proj.transform(e.coordinate, destinationPro, sourcePro);//这里是把获取到的e.coordinate的值(鼠标滑动时在地图上产生的数值)转换为经纬度。
                locaLongitude = featureCoords[0];//经度
                localLatitude = featureCoords[1];//维度
                var _thisLayer = map.getLayerByName("localArea");//获取名为localArea的图层
                var features = _thisLayer.get('source').getFeatures();
                for (var j = 0; j < features.length; j++) {
                    var polygonGeometry = features[j].getGeometry();
                    if (polygonGeometry.intersectsCoordinate(e.coordinate)) {
                        isLocationArr.push("1");//如果坐标在图层上的时候则插入"1"
                    } else {
                        isLocationArr.push("0");//否则插入"0"
                    }
                }

猜你喜欢

转载自blog.csdn.net/qq_42610806/article/details/86608543