2013-07-13 46 views
1

我有一個OpenLayers map,它在矢量圖層中繪製特徵。這些功能是可選的,並有選擇彈出。不幸的是,在許多情況下,這些特徵重疊,因此選擇某些特徵是不可能的。我認爲我需要做的是解決這個問題,就是改變我的選擇控件,以便它使用點擊處理程序並在此處搜索地圖上的特徵。我需要寫什麼樣的功能?有沒有這樣的例子實施之前?javascript函數搜索覆蓋像素的所有OpenLayers矢量特徵

這是功能是如何得出:

var vector_Layer = new OpenLayers.Layer.Vector(); 

function GetFeaturesFromKMLString (strKML) { 
    var format = new OpenLayers.Format.KML({ 
    'internalProjection': new OpenLayers.Projection("EPSG:900913"), 
    'extranalProjection': new OpenLayers.Projection("EPSG:4326")  
    }); 
    return format.read(strKML); 
}; 

vector_Layer.addFeatures(GetFeaturesFromKMLString('$newkml')); 

這就是圖層的當前選擇:

var select = new OpenLayers.Control.SelectFeature(vector_Layer, {clickout: true}); 
     vector_Layer.events.on({ 
      "featureselected": onFeatureSelect, 
      "featureunselected": onFeatureUnselect}); 



     map.addControl(select); 
     select.activate(); 

     select.handlers['feature'].stopDown = false; 
     select.handlers['feature'].stopUp = false; 

這裏是click事件偵聽我打算用:

OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, {     
      defaultHandlerOptions: { 
       'single': true, 
       'double': false, 
       'pixelTolerance': 0, 
       'stopSingle': false, 
       'stopDouble': false 
      }, 

      initialize: function(options) { 
       this.handlerOptions = OpenLayers.Util.extend(
        {}, this.defaultHandlerOptions 
       ); 
       OpenLayers.Control.prototype.initialize.apply(
        this, arguments 
       ); 
       this.handler = new OpenLayers.Handler.Click(
        this, { 
         'click': this.onClick 
        }, this.handlerOptions 
       ); 
      }, 

      onClick: function(evt) { 
       //function that seachers for and selects features at this point 
      }, 

回答