好吧,当我测试这段代码时
var map;
function mapInit(element){
map = new OpenLayers.Map(element);
var osm = new OpenLayers.Layer.OSM();
var vectors = new OpenLayers.Layer.Vector("Vector Layer", {renderers: renderer});
var renderer = OpenLayers.Util.getParameters(window.location.href).renderer;
renderer = (renderer) ? [renderer] : OpenLayers.Layer.Vector.prototype.renderers;
map.addLayers([osm, vectors]);
map.zoomToMaxExtent();
var add = new OpenLayers.Control.DrawFeature(vectors,OpenLayers.Handler.Point, {
featureAdded: getInfoFeature,
multi: false
});
map.addControl(add);
add.activate();
}
function getInfoFeature(event){
var coords = event.lonlat;
console.log(coords);
}
mapInit('siteMap');
添加功能效果很好,但坐标为空。可能我错过了什么?是否也可以设置最大的可添加功能?