有没有人有一个如何使用打开图层点的事件处理程序的示例?
由于
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 :(得分: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应该对您有所帮助。