2011-11-27 70 views
2

有没有人有如何使用具有开放图层点的事件处理程序的示例?打开图层点事件

感谢

function mapCreate(lon,lat){ 
     map = new OpenLayers.Map("map1"); 
     var osm = new OpenLayers.Layer.OSM(); 
     vectors = new OpenLayers.Layer.Vector("Vector Layer"); 
     map.addLayer(osm); 
     var center = new OpenLayers.LonLat(lon,lat).transform(
      new OpenLayers.Projection("EPSG:4326"), 
      map.getProjectionObject() 
     ); 

     point = new OpenLayers.Geometry.Point(center.lon,center.lat); 
     vectors.addFeatures([new OpenLayers.Feature.Vector(point)]); 
     drag = new OpenLayers.Control.DragFeature(vectors); 
     //map.addLayer(vectors); 
     map.addControl(drag); 
     drag.activate(); 
     map.setCenter(center, 15); 
     map.addLayer(vectors); 
     point.events.register('moveend',point, function(evt){ 
      alert('hello'); 
     }); 

    } 

这是我所尝试过的例子,由于某种原因,这部分不工作

point.events.register('moveend',point, function(evt){ 
       alert('hello'); 
      }); 
+0

感谢代码更新,我没有区分标记和点,你怎么样?标记是人们用来识别给定点的东西,不是? – jcolebrand

+0

我区分这两个因为点属于矢量和标记不。我认为。从查看标记的api,可以找到可以解决我的问题的事件属性。 – Paul

+0

啊,非常好,我明白你的意思了。另外,希望你现在可以解决它。 – jcolebrand

回答

0

下面是我在过去使用一些类似的代码在页面右侧的div列表上悬停显示标记。包括它,因为它展示了我过去的观点。我不认为这是你想要的。

/* Included for per-item hovering from the paginated layer. */ 
function onFeatureSelected(event) { 
    hoveredItem = $(this).attr('lookup'); 

    /* Do something here to indicate the onhover */ 
    // find the layer pagination id 
    var feature = findFeatureById(hoveredItem); 

    if (feature) { 

     // use the pagination id to find the event, and then trigger the click for that event to show the popup 
     // also, pass a null event, since we don't necessarily have one. 
     feature.marker.events.listeners.click[0].func.call(feature, event) 
    } 
} 
function onFeatureUnselected(event) { 
    /* Do something here to indicate the onhover */ 
    // find the layer pagination id 
    var feature = findFeatureById(hoveredItem); 

    if (feature) { 

     // use the pagination id to find the event, and then trigger the click for that event to show the popup 
     // also, pass a null event, since we don't necessarily have one. 
     feature.marker.events.listeners.click[0].func.call(feature, event) 
    } 

    /* Do something here to stop the indication of the onhover */ 

    hoveredItem = null; 
} 

function findFeatureById(featureId) { 
    for (var key in map.layers) { 
     var layer = map.layers[key]; 
     if (layer.hasOwnProperty('features')) { 
      for (var key1 in layer.features) { 
       var feature = layer.features[key1]; 
       if (feature.hasOwnProperty('id') && feature.id == featureId) { 
        return feature; 
       } 
      } 
     } 
    } 
    return null; 
} 

如果你想为正在创建它这个加的地步,我必须刷新我就怎么说在过去已经做内存。或者,GIS SE应该对您有所帮助。