Siguiendo los ejemplos en Openlayers.org, creé una capa de vector de puntos (con superposiciones, etc.). Los puntos se muestran como puntos de clúster como en el ejemplo aquí:
Ejemplo de clúster de Openlayers
Ahora, necesito filtrar los puntos según sus propiedades, por ejemplo, lab_data = 'yes', sampling_year > 1990. El filtrado afecta la cantidad de puntos dentro de los grupos.
Hasta ahora no he encontrado un método para excluir características de mis objetos Fuente o Capa. Incluso no pude acceder a las funciones y sus propiedades. A partir de ahí pude construir bucles y condiciones.
¿Alguien tiene una idea de cómo se hace?
// Read GeoJson point locations var pointLocations = new ol.source.Vector({ url: 'data/samplingLocations.json', format: new ol.format.GeoJSON() }); // create point cluster var pointCluster = new ol.source.Cluster({ distance: 50, source: pointLocations }); // create simple style for single points and clusters var getStyle = function(feature) { var length = feature.get('features').length; if (length > 1) { style = new ol.style.Style({ image: new ol.style.Circle({ radius: 20, fill: new ol.style.Fill({ color: "red" }), }), }) } else { style = new ol.style.Style({ image: new ol.style.Circle({ radius: 10, fill: new ol.style.Fill({ color: "black" }), }), }) } return style; }; // create a vector layer var vectorLayer = new ol.layer.Vector({ id: "points", source: pointCluster, style: getStyle }); // create the map var map = new ol.Map({ layers: [vectorLayer], target: 'map', view: new ol.View({ center: [895571,5911157], zoom: 8, }) });Hasta ahora, algunos de mis intentos fallidos de acceder a las propiedades:
console.log( pointLocations.getSource().getFeatures()[0].getProperties().values) console.log( vectorLayer.getSource().getFeatures()[0].get('values') )¡Toda ayuda es muy apreciada!
Puede filtrar con una función de geometría, por ejemplo:
var pointCluster = new ol.source.Cluster({ distance: 50, source: pointLocations, geometryFunction: function(feature) { if (feature.get('lab_data') == 'yes' && feature.get('sampling_year') > 1990) { return feature.getGeometry(); } else { return null; } } });