[英]Openlayers 4 trigger select feature on map
我有一個網站,您在哪里有地圖以及地圖中的區域列表。
當您單擊區域時,我在地圖上添加了選擇事件。
// add select features to the map
map.addInteraction(select);
var selectedFeatures = select.getFeatures();
selectedFeatures.on(['add', 'remove'], function() {
var names = selectedFeatures.getArray();
var areasel = [];
names.forEach(function(feature) {
areasel.push(feature.getProperties().Name);
var theCode = feature.getProperties().Code;
$('#bt'+ theCode).click();
});
}); // end on select
當然,選擇功能時會更改顏色。
單擊列表時如何觸發同一事件?
$('<p>', {
text: '...'
}).appendTo('#li' + s.code);
$('<button />', {
id: 'bt' + s.code,
class: "custbtn live",
text: "Live",
url: s.url
}).click(function(e) {
// Which function do I need to parse?
// At this point I can have the Name of the feature that i want to select
// s.name but how can I use it to trigger the event on the map?
}).appendTo('#li' + s.code);
這是WFS矢量層。
// UK map source
var vectorSource = new ol.source.Vector({
format: new ol.format.WFS(),
url: function(extent) {
return 'http://www.trafficorders.uk/cgi-bin/mapserv?map=/var/www/vhosts/trafficorders.uk/httpdocs/maps/wfsareas.map&service=WFS&' +
'version=1.1.0&request=GetFeature&typename=la_areas&' +
'outputFormat=text/xml; subtype=gml/3.1.1&srsname=EPSG:27700';
},
strategy: ol.loadingstrategy.all
});
// UK map layer
var vectorLayer = new ol.layer.Vector({
source: vectorSource,
style: styleFunction
});
您是否只是嘗試過將功能推入selectedFeatures
數組中?
var selectedFeatures = select.getFeatures();
$('<p>', {
text: '...'
}).appendTo('#li' + s.code);
$('<button />', {
id: 'bt' + s.code,
class: "custbtn live",
text: "Live",
url: s.url
}).click(function(e) {
selectedFeatures.push(s); //if 's' is actually the feature you got from openLayer?
}).appendTo('#li' + s.code);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.