我正在尝试简单的事情,您可以在这里看到一个演示:http://www.jsfiddle.net/vve8x/19/

此错误仅出现在Firefox中,因此要看到它一次按一个链接(将需要您到纽约或以色列),然后按其他链接。错误是它不会向我展示该位置的瓷砖,而是会向我展示Div的背景。

PS在Chrome中,这是完美无缺的。

我不知道这是线索还是可能会使您感到困惑,如果在按下纽约或以色列链接之间,请按“查看世界”链接,它将允许您看到另一个位置。

全部参考来源

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <body>

    <a href="#" onclick="javascript:show1()">show me NY</a>
    <a href="#" onclick="javascript:show2()">show me TLV</a>
    <a href="#" onclick="javascript:map.zoomToExtent(map.getMaxExtent());">show world map(a "workaround"</a>


    <div id='myMap' style="height: 600px; width: 600px; position: relative"></div>

    <script src="http://openlayers.org/api/OpenLayers.js" type="text/javascript"></script>
    <script src="http://developers.cloudmade.com/attachments/download/58/cloudmade.js" type="text/javascript"></script>
    <script type="text/javascript" charset="utf-8">
        map = new OpenLayers.Map("myMap", {
            controls: [
                new OpenLayers.Control.Navigation(),
                new OpenLayers.Control.PanZoomBar()
            ]
        });

        var cloudmade = new OpenLayers.Layer.CloudMade("CloudMade", {
            key: 'd5da652e33e6486ba62fca3d18ba70c9'
        });
        map.addLayer(cloudmade);

        var epsg4326 = new OpenLayers.Projection("EPSG:4326");

        map.setCenter(new OpenLayers.LonLat(40, 32), 2);

        show1 = function(){
        var bound1 = new OpenLayers.Bounds(-8236567.917898,4972686.066032,-8236148.409989,4972889.624407);
            map.zoomToExtent(bound1); // to NY
        };

        show2 = function(e){
            var bound2 = new OpenLayers.Bounds(3874818.203389,3773932.267033,3875217.305962,3774226.370443);   
            map.zoomToExtent(bound2); // to Israel
            return false;
        };

    </script>
    </body>
</html>
有帮助吗?

解决方案

Mymap_openlayers_container在瓷砖不可见时具有以下CSS:

位置:绝对; Z-INDEX:749;左:-2.02815e+7px;顶部:-2007340px;

如果您周围更改这些,则可以看到正确的瓷砖已加载,因此很可能是jsfiddle弄乱它们。当瓷砖不显示时,它们也有奇怪的值。

更新:

本地测试还会产生问题,因此排除JSFIDDLE。

修复程序是通过调用函数,例如:

        updateCSS = function(){
            OpenLayers_Container = document.getElementById("myMap_OpenLayers_Container").style.left = "0px";
        }

这看起来像是一个错误,尽管如果它在开放层中,或者很难说出CloudMade Layer属性 - 我想像后者,或者它将是广泛报道的错误。 openlayers.js中的相关代码似乎是:

centerLayerContainer: function(lonlat){
    var originPx = this.getViewPortPxFromLonLat(this.layerContainerOrigin);
    var newPx = this.getViewPortPxFromLonLat(lonlat);
    if ((originPx != null) && (newPx != null)) {
        this.layerContainerDiv.style.left = Math.round(originPx.x - newPx.x) + "px";
        this.layerContainerDiv.style.top = Math.round(originPx.y - newPx.y) + "px";
    }

其他提示

我也遇到了这个问题,事实证明我没有像我想象的那样设置地图的中心。如果您首先致电Map.setCenter(),则问题消失了。例如:

var newCenter = new OpenLayers.Lonlat(longitude, latitude)
    .transform(new OpenLayers.Projection('ESPG:4326'),
               this.map.getProjectionObject());

this.map.setCenter(newCenter);

希望这对接下来有问题的人有帮助。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top