简体   繁体   English

使用PNG或JPEG进行OpenLayers地图(缩放/缩放问题)

[英]Using an PNG or JPEG for Map with OpenLayers (Scale/Zoom Problem)

I am using an image to display my map with OpenLayers. 我正在使用图像来显示我的OpenLayers地图。 My JS code looks like this: 我的JS代码如下所示:

map = new OpenLayers.Map('map');

var options = {numZoomLevels: 7,
                isBaseLayer: true,
                };

var globe = new OpenLayers.Layer.Image(
    'Globe ESA',
    'http://upload.wikimedia.org/wikipedia/commons/0/07/World_map_blank_black_lines_4500px.gif',
    new OpenLayers.Bounds(-180, -90, 180, 90),
    new OpenLayers.Size(4500, 2234),
    options);

map.addLayers(globe);

markers = new OpenLayers.Layer.Markers("markers");
map.addLayer(markers);

map.addControl(new OpenLayers.Control.LayerSwitcher());
map.zoomToMaxExtent();
map.addControl(new OpenLayers.Control.MousePosition());

My CSS is: 我的CSS是:

#map {
    width: 640px;
    height: 480px;
    border: 1px solid black;
}

But I can't get OpenLayers to scale down the large image. 但我不能让OpenLayers缩小大图像。 It is always display at full resolution and I can't zoom out to display the whole globe. 它始终以全分辨率显示,我无法缩小显示整个地球。 Help please. 请帮助。

You need to set the size of the image as it should display when fully zoomed out. 您需要设置完全缩小时应显示的图像大小。

var globe = new OpenLayers.Layer.Image(
    'Globe ESA',
    'http://upload.wikimedia.org/wikipedia/commonS/0/07/World_map_blank_black_lines_4500px.gif',
    new OpenLayers.Bounds(-180, -90, 180, 90),
    new OpenLayers.Size(1125,558),
    options);

I changed the size to one fourth of the size of the original. 我将尺寸改为原尺寸的四分之一。 You could make this smaller if you wanted it even more zoomed out. 如果您想要缩小它,可以将其缩小。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM