我的代码完全正常,除了每次点击/悬停在“标记”上的事实,openLayer尝试从我的localserver检索一些图像(.png)。这是我的代码,并且没有直接指定图像。我不知道要覆盖什么来禁止这种行为:
这是我“onSelect”的错误:
GET http://localhost:8888/img/cloud-popup-relative.png 404 (Not Found)
这是我的代码。我希望有人可以提供帮助,因为重复的GET请求会导致性能下降!
var lonlat = convertProjectionToSphere(location);
console.log(lonlat);
var pointFeatures = [];
var pointGeometry = new OpenLayers.Geometry.Point(lonlat.lon, lonlat.lat);
var pointFeature = new OpenLayers.Feature.Vector(
pointGeometry,
null,
{
pointRadius: 16,
fillOpacity: 0.7,
externalGraphic:'img/mapIcons/Multi-Wave-test.png'
});
pointFeatures.push(pointFeature);
// Add features to the layer
var pointLayer = map.getLayer('Vectors');
pointLayer.addFeatures(pointFeatures);
// Add select feature control required to trigger events on the vector layer.
var selectControl = new OpenLayers.Control.SelectFeature(pointLayer, {
hover: true,
onSelect: function(feature) { // last point in my code from the stack trace
var layer = feature.layer;
feature.style.fillOpacity = 1;
feature.style.pointRadius = 20;
//layer.drawFeature(feature);
var content = '<div style="background-color:white;"><strong>Feature:</strong>'+
'<br/>' + feature.id +
'<br/><br/><strong>Location:</strong>'+
'<br/>' + feature.geometry +'</div>';
var popup = new OpenLayers.Popup.FramedCloud(
feature.id+"_popup",
feature.geometry.getBounds().
getCenterLonLat(),
new OpenLayers.Size(250, 100),
content,
null, // anchor
true, // closeBox exists
null); //closeBoxCallback
feature.popup = popup;
map.addPopup(popup);
},
onUnselect: function(feature) {
var layer = feature.layer;
feature.style.fillOpacity = 1;
feature.style.pointRadius = 16;
feature.renderIntent = null;
layer.drawFeature(feature);
map.removePopup(feature.popup);
}
});
map.addControl(selectControl);
selectControl.activate();
答案 0 :(得分:0)
您正在使用“FramedCloud”弹出窗口。 OpenLayers想要加载的图像是该弹出窗口的边界。该图像包含在OpenLayers发行版附带的“img”文件夹中。 您可以通过OpenLayers.ImgPath更改images文件夹的路径。这是一个link。 另外,您可以使用像Anchored这样更简单的弹出式样式。我认为它不使用图像作为其框架。