Skip rendering highlighted feature in vector-layer example
This commit is contained in:
@@ -36,6 +36,7 @@ var style = new ol.style.Style({
|
|||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var vectorLayer;
|
||||||
$.getJSON('data/countries.geojson', function(data) {
|
$.getJSON('data/countries.geojson', function(data) {
|
||||||
var format = new ol.format.GeoJSON();
|
var format = new ol.format.GeoJSON();
|
||||||
var transformFn = ol.proj.getTransform('EPSG:4326', 'EPSG:3857');
|
var transformFn = ol.proj.getTransform('EPSG:4326', 'EPSG:3857');
|
||||||
@@ -45,12 +46,13 @@ $.getJSON('data/countries.geojson', function(data) {
|
|||||||
feature.setGeometry(geometry);
|
feature.setGeometry(geometry);
|
||||||
vectorSource.addFeature(feature);
|
vectorSource.addFeature(feature);
|
||||||
});
|
});
|
||||||
map.getLayers().push(new ol.layer.Vector({
|
vectorLayer = new ol.layer.Vector({
|
||||||
source: vectorSource,
|
source: vectorSource,
|
||||||
styleFunction: function(feature) {
|
styleFunction: function(feature) {
|
||||||
return style;
|
return style;
|
||||||
}
|
}
|
||||||
}));
|
});
|
||||||
|
map.getLayers().push(vectorLayer);
|
||||||
});
|
});
|
||||||
|
|
||||||
var highlight;
|
var highlight;
|
||||||
@@ -68,6 +70,13 @@ var displayFeatureInfo = function(coordinate) {
|
|||||||
}
|
}
|
||||||
if (highlight !== oldHighlight) {
|
if (highlight !== oldHighlight) {
|
||||||
map.requestRenderFrame();
|
map.requestRenderFrame();
|
||||||
|
if (highlight) {
|
||||||
|
vectorLayer.setRenderGeometryFunction(function(geometry) {
|
||||||
|
return geometry !== highlight.getGeometry();
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
vectorLayer.setRenderGeometryFunction(undefined);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user