このGoogle の例のように、OpenLayers で適切なクラスタリングを行う方法を知っていますか?
6 に答える
上記の例でpointStyleにラベルを追加し、このラベルのコンテキストを説明できます。コードは次のようになります。
var pointStyle = new OpenLayers.Style({
// ...
'label': "${label}",
// ...
}, {
context: {
// ...
label: function(feature) {
// clustered features count or blank if feature is not a cluster
return feature.cluster ? feature.cluster.length : "";
}
// ..
}
});
var styleMap = new OpenLayers.StyleMap({
'default': pointStyle,
});
var googleLikeLayer = new OpenLayers.Layer.Vector("GoogleLikeLayer", {
// ...
styleMap : styleMap,
// ...
});
OpenLayers.Strategy.Cluster
クラスタリングに使用します。
OpenLayers のいわゆる AnimatedCluster 戦略を実装しました。詳細については、http: //www.acuriousanimal.com/2012/08/19/animated-marker-cluster-strategy-for-openlayers.htmlを参照してください。
これは最初のバージョンにすぎませんが、クラスターに素敵なアニメーションを追加します。改善すべき点はたくさんありますが、それは出発点です。
イゴルティが言ったように、これを行うことができます。ソリューションは OpenLayers.Strategy.Cluster クラスを使用し、レイヤーを OpenLayers.Style クラスでスタイリングします...
スタイリング用:
var pointStyle = new OpenLayers.Style({
'default': new OpenLayers.Style({
'pointRadius': '${radius}',
'externalGraphic': '${getgraph}'
....
},{
context:{
radius: function(feature){
return Math.min(feature.attributes.count,7)+3;
},{
getgraph : function(feature){
return 'ol/img/googlelike.png';
}}}};
それはあなたを助けなければなりません、あなたにもっと力を!
レイヤーに追加されたカスタム属性に基づくクラスタリングの JSfiddle を次に示します。私はこれに少し苦労したので、ここに入れました。また、クラスター化されたデータでズームアウトしたときの要約円グラフ画像の作成も示していますhttp://jsfiddle.net/alexcpn/518p59k4/
このOpenLayers Advanced Clusteringを説明するための小さな openlayer チュートリアルも作成しました
var getClusterCount = function (feature) {
var clustercount = {};
var planningcount = 0;
var onaircount = 0;
var inerrorcount = 0;
for (var i = 0; i < feature.cluster.length; i++) {
if (feature.cluster[i].attributes.cluster) {
//THE MOST IMPORTANT LINE IS THE ONE BELOW, While clustering open layers removes the orginial feature layer with its own. So to get the attributes of the feature you have added add it to the openlayer created feature layer
feature.attributes.cluster = feature.cluster[i].attributes.cluster;
switch (feature.cluster[i].attributes.cluster) {
......
return clustercount;
};