例如,我有一个由两个多边形组成的多面体。我可以使用modifyFeature控件和delete-key删除顶点。但是,modifyFeature控件不允许我完全删除多边形,因为它必须包含至少3个顶点。如何从多面体功能中完全删除多边形(使用删除键)? OpenLayers是否有适当的控件或插件?
我自己尝试修补控件,但这导致了多个小错误。所以我想在我花费大量时间来解决这些问题之前,先询问是否有人已经这样做了。
答案 0 :(得分:0)
removeComponent: function(point) {
var removed = this.components && (this.components.length > 3);
if (removed) {
//remove last point
this.components.pop();
//remove our point
OpenLayers.Geometry.Collection.prototype.removeComponent.apply(this,
arguments);
//append copy of first point
var firstPoint = this.components[0];
OpenLayers.Geometry.Collection.prototype.addComponent.apply(this,
[firstPoint]);
//bm extension: possibility to delete geometry from multigeometries
} else if (this.components && this.parent && this.parent.parent && this.parent.parent.CLASS_NAME === "OpenLayers.Geometry.MultiPolygon") {
//polygon with hole
if (this.parent.components.length > 1) {
for (var i = 0; i < this.parent.components.length && this.parent.components.length > 1; i++) {
if (this.parent.components[i].id === this.id) {
OpenLayers.Util.removeItem(this.parent.components, this.parent.components[i]);
this.parent.clearBounds();
return true;
}
}
}
//seperate polygon
for (var i = 0; i < this.parent.parent.components.length && this.parent.parent.components.length > 1; i++) {
if (this.parent.parent.components[i].id === this.parent.id) {
OpenLayers.Util.removeItem(this.parent.parent.components, this.parent.parent.components[i]);
this.parent.parent.clearBounds();
return true;
}
}
}
return removed;
},