2013-03-08 58 views
-1

我有一個顯示從KML文件(基本上象的sundials example)導入的矢量層的頁面。它可以很好地工作,既可以使用固定策略,也可以同時使用固定策略和CLUSTER策略。的OpenLayers羣集策略 - 顯示自定義圖標爲1個特徵簇

我想創建混合顯示器,而「的1個特徵簇」將與<Style><IconStyle><Icon><href>img/arrowRed.png下包含在KML文件中的原始自定義圖標,例如被顯示。

現在,如果我使用羣集策略,使用默認圖標(黃色磁盤)顯示1(功能)的羣集。

我寧願不使用任何不是標準開放層的插件或庫。 有什麼建議嗎?

低於原使用JavaScript代碼集羣的一部分(刪除集羣戰略宣言new OpenLayers.Strategy.Cluster()和自定義圖標的顯示就好了):

var urlKMLClient = 'KMLClientsAll.kml'; 
var layerKMLClient = new OpenLayers.Layer.Vector("Clients", { 
     strategies: [new OpenLayers.Strategy.Fixed(), new OpenLayers.Strategy.Cluster(), refresh], 
     protocol: new OpenLayers.Protocol.HTTP({ 
      url: urlKMLClient, 
      format: new OpenLayers.Format.KML({ 
       extractStyles: true, 
       extractAttributes: true, 
       maxDepth: 2 
      }) 
     }) 
    }); 

WITHOUT CLUSTER

看到客戶端自定義圖標(綠色標誌)讓位於以下集羣默認圖標(黃色磁盤)

WITH CLUSTER

回答

3

用途:new OpenLayers.Strategy.Cluster({threshold:2})這使得薩德孤立點他們不是在一個集羣。

(是GIS論壇同一問題的答案的重複)

0

找到了解決辦法在this GIS question

變化集羣戰略,以大於1上面的代碼將成爲:

var clusterStrategy = new OpenLayers.Strategy.Cluster({ distance: 35, threshold: 2 }); 
var urlKMLClient = 'KMLClientsAll.kml'; 
var layerKMLClient = new OpenLayers.Layer.Vector("Clients", { 
     strategies: [new OpenLayers.Strategy.Fixed(), clusterStrategy, refresh], 
     protocol: new OpenLayers.Protocol.HTTP({ 
      url: urlKMLClient, 
      format: new OpenLayers.Format.KML({ 
       extractStyles: true, 
       extractAttributes: true, 
       maxDepth: 2 
      }) 
     }) 
    });