尝试使用它 - http://openlayers.org/dev/examples/SLDSelect.html 例如:我有选择功能(框),它允许我选择图层上的功能。但它是盒子类型的。现在我正在尝试进行相同的选择,但使用多边形样式。就像绘制新多边形一样,但该多边形内的内容将被选择。我是否在尝试使用此 SLD 选择时寻找正确的路径,还是有其他更好的方法?
对任何解决方案持开放态度。
谢谢。
尝试使用它 - http://openlayers.org/dev/examples/SLDSelect.html 例如:我有选择功能(框),它允许我选择图层上的功能。但它是盒子类型的。现在我正在尝试进行相同的选择,但使用多边形样式。就像绘制新多边形一样,但该多边形内的内容将被选择。我是否在尝试使用此 SLD 选择时寻找正确的路径,还是有其他更好的方法?
对任何解决方案持开放态度。
谢谢。
在这个 plunker 中,我使用了interaction.Draw 创建了一个多边形。多边形完成后,它会查找多边形范围内的所有特征点并选择它们。
以下是draw.on('drawend',...
听众的摘录:
draw.on('drawend', function(e) {
e.preventDefault();
//stop a click select from overriding selection made by polygon
setTimeout(function(){
select.setActive(true)
},300);
// features that intersect the box are added to the collection of
// selected features, and their names are displayed in the "info"
// div
var extent = e.feature.getGeometry().getExtent();
//pointsLayer is the vector layer with the point features
pointsLayer.getSource().forEachFeatureIntersectingExtent(extent, function(feature) {
selectedFeatures.push(feature);
});
});
从 GIS StackEchange 站点:
function buildIt() {//START FUNCTION buildIt
//CREATE A NEW EMPTY VECTOR LAYER
var polygonAdHoc = new OpenLayers.Layer.Vector("Poly Layer");
//ADD THE NEW VECTOR LAYER TO THE OPENLAYERS MAP
map.addLayer(polygonAdHoc);
//SET A VARIABLE TO THE NAME OF THE EXISTING LAYER THAT WILL BE TESTED FOR INTERSECTION WITH THE USER CREATED POLYGON
//I CHOSE TO GET THE LAYER BY NAME BUT YOU MIGHT CHOOSE TO DO IT ANOTHER WAY
var standLyr = map.getLayersByName("nameOfTheVectorLayerYouWantToTestForIntersection");
//CREATE A DRAW FEATURE CONTROL FOR THE USER CREATED VECTOR LAYER
var draw = new OpenLayers.Control.DrawFeature(polygonAdHoc, OpenLayers.Handler.Polygon);
//ADD THE DRAW FEATURE CONTROL TO THE MAP
map.addControl(draw);
//ACTIVATE THE DRAW FEATURE CONTROL
draw.activate();
//WHEN THE USER FINISHES DRAWING THE AD-HOC POLYGON THE beforefeatureadded EVENT WILL FIRE
polygonAdHoc.events.on({
beforefeatureadded: function (event) {
poly = event.feature.geometry;//SET A VARIABLE TO THE USERDRAWN POLYGONS GEOMETRY
//alert("polygonAdHoc.features[0].geometry: " + poly);//IF YOU WANT TO SEE THE GEOMETRY COORDINATES UNCOMMENT THIS LINE
for (var a = 0; a < standLyr[0].features.length; a++) {//LOOP THRU THE STANDS FEATURES OF THE LAYER YOU WANT TO TEST FOR INTERSECTION WITH THE USER DRAWN POLYGON
if (poly.intersects(standLyr[0].features[a].geometry)) {//IF THE USER DRAWN POLYGON INTERSECTS THE TARGET LAYERS FEATURE REPRESENTED BY THE VARIABLE "a" THEN
//IDENTIFY THE FEATURE THAT INTERSECTS
//FOR SIMPLICITIES SAKE I CHOSE TO JUST FIRE AN ALERT
//MY ACTUAL APP ADDS EACH SELECTED FEATURE TO A SELECT FEATURE CONTROL AND HIGHLIGHTS EACH POLYGON ON THE MAP
alert("stands feature intersection: " + standLyr[0].features[a].attributes['nameOfAttribute']);
}//END OF IF STATEMENT
}//END OF FOR STATEMENT
draw.deactivate();//I ONLY WANT THE USER TO BE ABLE TO DRAW ONE AD-HOC POLYGON
//SO I DEACTIVATE THE DRAW FEATURE CONTROL AFTER THEY CREATE THE FIRST POLYGON
return false;
}//END OF beforefeatureadded FUNCTION
});//END OF polygonAdHoc.events.on
}//END OF buildIt FUNCTION