Я хочу иметь возможность выбрать, будут ли выделены многоугольники или нет.Как активировать и деактивировать следующий скрипт?
var highlightStyle = new ol.style.Style({
stroke: new ol.style.Stroke({
color: 'navy',
width: 1
}),
fill: new ol.style.Fill({
color: 'rgba(255,165,0,0.5)'
}),
text: new ol.style.Text({
font: '16px Arial',
fill: new ol.style.Fill({
color: 'white'
}),
stroke: new ol.style.Stroke({
color: 'white',
width: 0
}) ,overflow:true
,placement:'point'
,backgroundFill: new ol.style.Fill({
color: 'none'
})
,backgroundStroke: new ol.style.Stroke({
color: 'none',
width: 0
})
,padding:[3,3,3,3]
,offsetY: -60
})
});
var featureOverlay = new ol.layer.Vector({
source: new ol.source.Vector(),
map: map,
style: function(feature) {
highlightStyle.getText().setText(feature.get('text_text'));
return highlightStyle;
}
});
var highlight;
var displayFeatureInfo = function(pixel) {
var feature = map.forEachFeatureAtPixel(pixel, function(feature) {
return feature;
});
if (feature !== highlight) {
if (highlight) {
featureOverlay.getSource().removeFeature(highlight);
}
if (feature) {
featureOverlay.getSource().addFeature(feature);
}
highlight = feature;
}
};
map.on('pointermove', function(evt) {
if (evt.dragging) {
return;
}
var pixel = map.getEventPixel(evt.originalEvent);
displayFeatureInfo(pixel);
});
map.on('click', function(evt) {
displayFeatureInfo(evt.pixel);
});
Я хочу активировать его с помощью флажка.Я попытался создать объект из него и удалить его, но это не имеет никакого эффекта.Я также создал метод в объекте и удалил его, но он также не принес ожидаемого результата.