Javascript 开放层点事件
有没有人举过一个关于如何使用开放层事件处理程序的例子 谢谢Javascript 开放层点事件,javascript,openlayers,Javascript,Openlayers,有没有人举过一个关于如何使用开放层事件处理程序的例子 谢谢 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); v
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');
});
下面是一些类似的代码,我过去曾使用它们在页面右侧的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应该会对您有所帮助。谢谢您的代码更新,我不区分标记和点,您怎么办?标记是人们用来识别给定点的东西,不是吗?我区分这两个点是因为点属于向量,而标记不属于向量。我想。从标记的api来看,有一个事件属性可以解决我的问题。啊,很好,我明白你的意思了。另外,希望你现在能解决这个问题。