我的代码工作得非常好,除了每次我单击/悬停在“标记”上时,openLayer 都会尝试从我的本地服务器检索一些图像(.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();