Openlayers 3 OpenLayers 3中的Multiselect功能不起作用
我是OpenLayers的新手,我做了一个简单的例子,尝试在地图上绘制多边形。绘图后,我想能够多选择多边形按下shift键,点击进一步处理。即使OpenLayers示例页面上的一些示例非常接近,我也无法实现这一点。。。 这是我的代码(按“绘制”按钮并绘制两个多边形,按“停止”按钮退出绘制模式并尝试按住shift键进行多选):Openlayers 3 OpenLayers 3中的Multiselect功能不起作用,openlayers-3,Openlayers 3,我是OpenLayers的新手,我做了一个简单的例子,尝试在地图上绘制多边形。绘图后,我想能够多选择多边形按下shift键,点击进一步处理。即使OpenLayers示例页面上的一些示例非常接近,我也无法实现这一点。。。 这是我的代码(按“绘制”按钮并绘制两个多边形,按“停止”按钮退出绘制模式并尝试按住shift键进行多选): var引擎=此; var-draw=null; var map=新ol.map({ 目标:“地图”, 图层:[ 新ol.layer.Tile({ source:new o
var引擎=此;
var-draw=null;
var map=新ol.map({
目标:“地图”,
图层:[
新ol.layer.Tile({
source:new ol.source.MapQuest({layer:'osm'})
})
],
视图:新ol.view({
中心:[0,0],
缩放:2
})
});
var features=new ol.Collection();
var source=new ol.source.Vector({features:features});
var featureOverlay=新ol.layer.Vector({
资料来源:资料来源,
风格:新的ol风格({
填充:新的ol.style.fill({
颜色:“rgba(255,255,255,0.2)”
}),
笔划:新的ol风格笔划({
颜色:'#000000',
宽度:1
}),
图片:新ol.style.Circle({
半径:7,
填充:新的ol.style.fill({
颜色:'#000000'
})
})
})
});
功能覆盖。设置地图(地图);
$(“#fmsv_等高线”_elm”)。单击(函数(){
附加相互作用(“多边形”);
});
$(“#fmsv_stop_elm”)。单击(函数(){
如果(抽签)
映射。移除交互(绘制);
draw=null;
});
var selectClick=new ol.interaction.Select({
条件:ol.events.condition.click,
//addCondition:ol.events.condition.shiftKeyOnly,
//toggleCondition:ol.events.condition.never,
//removeCondition:ol.events.condition.altKeyOnly,
});
map.addInteraction(选择单击);
var selectedFeatures=select.getFeatures();
//选择点击('select',功能(e){
//});
函数addInteraction(drawmode){
如果(抽签)
映射。移除交互(绘制);
draw=新ol.interaction.draw({
特色:特色,,
类型:/**@type{ol.geom.GeometryType}*/(drawmode)
});
地图。添加交互作用(绘制);
}
使用map.addLayer(featureOverlay)
而不是featureOverlay.setMap(map)
非常感谢,成功了!我想我还在为openlayers中的概念绞尽脑汁。。。
<body>
<div>
<img src="stop.png" class="fmsv_map_btn" id="fmsv_stop_elm" title="Stop drawing" alt="Stop drawing">
<img src="draw.png" class="fmsv_map_btn" id="fmsv_contour_elm" title="Contour" alt="Contour">
</div>
<div width="600" height="600" id="map" class="map"></div>
<script>
var engine = this;
var draw = null;
var map = new ol.Map({
target: "map",
layers: [
new ol.layer.Tile({
source: new ol.source.MapQuest({ layer: 'osm' })
})
],
view: new ol.View({
center: [0,0],
zoom: 2
})
});
var features = new ol.Collection();
var source = new ol.source.Vector({ features: features });
var featureOverlay = new ol.layer.Vector({
source: source,
style: new ol.style.Style({
fill: new ol.style.Fill({
color: 'rgba(255, 255, 255, 0.2)'
}),
stroke: new ol.style.Stroke({
color: '#000000',
width: 1
}),
image: new ol.style.Circle({
radius: 7,
fill: new ol.style.Fill({
color: '#000000'
})
})
})
});
featureOverlay.setMap(map);
$("#fmsv_contour_elm").click(function () {
addInteraction("Polygon");
});
$("#fmsv_stop_elm").click(function () {
if (draw)
map.removeInteraction(draw);
draw = null;
});
var selectClick = new ol.interaction.Select({
condition: ol.events.condition.click,
//addCondition: ol.events.condition.shiftKeyOnly,
//toggleCondition: ol.events.condition.never,
//removeCondition: ol.events.condition.altKeyOnly,
});
map.addInteraction(selectClick);
var selectedFeatures = select.getFeatures();
//selectClick.on('select', function (e) {
//});
function addInteraction(drawmode) {
if (draw)
map.removeInteraction(draw);
draw = new ol.interaction.Draw({
features: features,
type: /** @type {ol.geom.GeometryType} */ (drawmode)
});
map.addInteraction(draw);
}
</script>
</body>