0

I'm using ol3/ol4 with ol-ext I create two layer:

clusterSource = new ol.source.Cluster({
    distance: distanceFt,
    source: new ol.source.Vector()
});
// Animated cluster layer
clusterLayer = new ol.layer.AnimatedCluster({
    name: 'Cluster',
    source: clusterSource,
    animationDuration: 700, //$("#animatecluster").prop('checked') ? 700 : 0,
    // Cluster style
    style: getStyle
});

layersArray.push(clusterLayer); // adding to array

sourceReclamos_Eventos = new ol.source.Cluster({
        distance: distanceFt,
        source: new ol.source.Vector()
    });
    capaReclamos_Eventos = new ol.layer.AnimatedCluster({
        name: "Reclamos_Eventos",
        source: sourceReclamos_Eventos,
        animationDuration: 700,
        style: getStyle
    });
    layersArray.push(capaReclamos_Eventos);

Later, add that layers in:

selectCluster = new ol.interaction.SelectCluster({
    layers: arraySelectCLuster,
    // Point radius: to calculate distance between the features
    pointRadius: 20,
    animate: true, //$("#animatesel").prop('checked'),
    // Feature style when it springs apart
    featureStyle: featureStyle,
    selectCluster: false,   // disable cluster selection
});

After load the layers, only persist the Features in the first layer, in the second layer the Features is removed (clear) after zoom changing... why?

please, help

EDIT

I'm adding features using clusterLayer.getSource().addFeatures() and capaReclamos_Eventos.getSource().addFeatures().

function addFeatures_Reclamos_Eventos(ffs, centrar) {
    var transform = ol.proj.getTransform('EPSG:4326', 'EPSG:3857');
    var features = [];
    for (var i = 0; i < ffs.length; i++) {
        features[i] = new ol.Feature();
        features[i].setProperties(ffs[i]);
        var geometry = new ol.geom.Point(transform([parseFloat(ffs[i].lon), parseFloat(ffs[i].lat)]));
        features[i].setGeometry(geometry);
    }
    qweFeature = features;
    capaReclamos_Eventos.getSource().addFeatures(features);
    removeloading('mapLoading');
    if (document.getElementById('botonFiltrar')) {
        document.getElementById('botonFiltrar').disabled = false;
    }
    if (centrar) {
        window.setTimeout(function () {
            var extent = capaReclamos_Eventos.getSource().getExtent();
            map.getView().fit(extent, map.getSize());
        }, 700);// 1/2 seg        
    }
}
SC-Gera
  • 11
  • 2
  • How do you add features to the vector sources for `clusterSource` and `sourceReclamos_Eventos` ? – Mike Mar 07 '19 at 10:51
  • I edited adding details of how i do it. – SC-Gera Mar 07 '19 at 12:44
  • `capaReclamos_Eventos.getSource()` will return `sourceReclamos_Eventos` which is a cluster source. The individual features which will OpenLayers will cluster should go in the vector source for `sourceReclamos_Eventos` which is `sourceReclamos_Eventos.getSource()` – Mike Mar 07 '19 at 12:58
  • Thanks! I do capaReclamos_Eventos.getSource().getSource().addFeatures() and now it work :D – SC-Gera Mar 11 '19 at 13:47

0 Answers0