绘制后无法 select 多边形
Can't select polygon after drawing it
我正在尝试以交互方式在地图上绘制单独样式的多边形。绘图效果很好,但我似乎无法 select 绘制的多边形来修改它们。我怀疑我对他们实际被吸引到哪里感到困惑:
var drawLayer = new ol.layer.Vector({
source: new ol.source.Vector()
});
map.addLayer( drawLayer );
var select = new ol.interaction.Select();
map.addInteraction( new ol.interaction.Modify({
features: select.getFeatures()
});
map.addInteraction( draw = new ol.interaction.Draw({
source: drawLayer.getSource(),
type: "Polygon"
});
draw.on('drawend', function( e ) {
var sty = new ol.style.Style( {
fill: new ol.style.Fill( { color: newCol } )
});
e.feature.setStyle( sty );
});
事实证明,在 select 激活之前,您需要通过扩展交互默认值来添加交互。仅使用 map.addInteraction()
添加它是必要的,但还不够。
featureSelect=new ol.interaction.Select();
map=new ol.Map( {
interactions: ol.interaction.defaults().extend([featureSelect]),
//...
});
我正在尝试以交互方式在地图上绘制单独样式的多边形。绘图效果很好,但我似乎无法 select 绘制的多边形来修改它们。我怀疑我对他们实际被吸引到哪里感到困惑:
var drawLayer = new ol.layer.Vector({
source: new ol.source.Vector()
});
map.addLayer( drawLayer );
var select = new ol.interaction.Select();
map.addInteraction( new ol.interaction.Modify({
features: select.getFeatures()
});
map.addInteraction( draw = new ol.interaction.Draw({
source: drawLayer.getSource(),
type: "Polygon"
});
draw.on('drawend', function( e ) {
var sty = new ol.style.Style( {
fill: new ol.style.Fill( { color: newCol } )
});
e.feature.setStyle( sty );
});
事实证明,在 select 激活之前,您需要通过扩展交互默认值来添加交互。仅使用 map.addInteraction()
添加它是必要的,但还不够。
featureSelect=new ol.interaction.Select();
map=new ol.Map( {
interactions: ol.interaction.defaults().extend([featureSelect]),
//...
});