2017-10-06 53 views
0

是否有一個參數可以設置要羣集的要素的最小半徑? - 當一組點或特徵在某一最小距離內時,它們形成一個簇,否則不是?如何配置功能需要在openlayers中形成羣集的距離3

ol.source.Cluster()有兩個看起來很有希望的參數,但似乎沒有按預期工作。

  • distance:簇之間的最小距離(以像素爲單位)。默認值爲20.

  • 範圍:表示範圍的數字數組:[minx,miny, maxx,maxy]。

回答

0

不太確定什麼「但似乎沒有按預期工作。」手段??它如何不按預期工作?

distanceol.source.Cluster的屬性告訴圖層何時根據設置的距離對對象進行分組。創建集羣層時可以更改它。例如:

var locationSource = new ol.source.Vector({ 
    url: loc_url, 
    format: new ol.format.GeoJSON({ 
    defaultDataProjection :'EPSG:3857' 
    }), 
    loader: vectorLoader, 
    strategy: ol.loadingstrategy.all 
}); 

var LOCclusterSource = new ol.source.Cluster({ 
    distance: 5, 
    source: locationSource 
}); 

我通常改變距離的對象,直到我找到所需distance所以組/集羣對象看起來直接在地圖上。

地圖圖層上的組對象的半徑可以通過地圖圖層的樣式函數進行更改。堆棧中存在很多樣式函數的例子。

這裏是一個入侵高達例如,我使用以增加羣集的半徑/組地圖層上對象,因此它是在視覺上明顯的是,它是一組/集羣對象:

注:可以具有不同的形狀在同一圖層上也使用樣式函數。 https://openlayers.org/en/latest/examples/regularshape.html

// Location Map Layer Properties 
var locLyrProps = { 
    "radius": 8, 
    "CORadius": 12, 
    "groupRadius": 10, 
    "borderWidth": 2, 
    "color": [0, 0, 0, 0.5], 
    "txtMaxRes": 20, 
    "txtOffsetY": -20 
}; 

var styleFunction = function() { 
    return function(feature,resolution) { 
    var style; 
    var props = locLyrProps; 
    var radius; 
    var lyrTyp; 
    var gotGroup = false; 
    var features = feature.get('features'); 

    if (features.length == 1) { //Individual map object because length = 1 
     style = new ol.style.Style({ //Square layer object 
     image: new ol.style.RegularShape({ 
      radius: radius, 
      points: 4, 
      angle: Math.PI/4, 
      fill: createFillStyle(feature), 
      stroke: createStrokeStyle(feature, resolution) 
     }), 
     text: createTextStyle(feature, resolution) 
     }); 
    } else { 
     var rad = props.radius; 
     if (features.length > 1) { //If cluster/group of features increase radius of group object so group objects stand out a bit 
     rad = props.groupRadius; //If cluster/group object is found, set cluster/group radius for it 
     gotGroup = true; 
     } 
     console.log('circle radius: ' + rad); 
     style = new ol.style.Style({ 
     image: new ol.style.Circle({ 
      radius: rad, 
      fill: createFillStyle(feature), 
      stroke: createStrokeStyle(feature, resolution, gotGroup) 
     }), 
     text: createTextStyle(feature, resolution, props, gotGroup) 
     }); 
    } 
    return [style]; 
    }; 
};