0

我的代码工作得非常好,除了每次我单击/悬停在“标记”上时,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();
4

1 回答 1

0

您正在使用“ FramedCloud ”弹出窗口。OpenLayers 想要加载的图像是该弹出窗口的边界。图像包含在 OpenLayers-distribution 附带的“img”文件夹中。您可以通过 OpenLayers.ImgPath 更改图像文件夹的路径。这是一个链接。或者,您可以使用更简单的弹出样式,例如锚定。我认为它不使用图像作为框架。

于 2012-10-18T13:53:50.927 回答