Witam
Mam taki skrypt:
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 false;
}
var pixel = null;
displayFeatureInfo(null);
});
map.on('click', function(evt) {
displayFeatureInfo(null);
});
Chciałbym go aktywować i dezaktywować za pomocą takiego zdarzenia:
$(document).on("change","#highlight_on_check", function () {
if(this.checked)
{
//.... tutaj aktywacja
}
if(!this.checked)
{
//.... tutaj dezaktywacja
}
});
Ni w ząb nie wiem jak się do tego zabrać. Myślałem o takim konstruktorze:
var High = {
init : function(){},
setActive : function(){}
}
High.init();
$(document).on("change","#highlight_on_check", function () {
if(this.checked)
{
High.setActive(true);
}
if(!this.checked)
{
High.setActive(false);
}
});
Jak aktywować - dezaktywować działanie tegi skryptu?