最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Using an PNG or JPEG for Map with OpenLayers (ScaleZoom Problem) - Stack Overflow

programmeradmin3浏览0评论

I am using an image to display my map with OpenLayers. My JS code looks like this:

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

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

var globe = new OpenLayers.Layer.Image(
    'Globe ESA',
    '.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:

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

But I can't get OpenLayers to scale down the large image. It is always display at full resolution and I can't zoom out to display the whole globe. Help please.

I am using an image to display my map with OpenLayers. My JS code looks like this:

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

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

var globe = new OpenLayers.Layer.Image(
    'Globe ESA',
    'http://upload.wikimedia/wikipedia/mons/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:

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

But I can't get OpenLayers to scale down the large image. It is always display at full resolution and I can't zoom out to display the whole globe. Help please.

Share Improve this question asked May 1, 2009 at 22:59 Bernie PerezBernie Perez 12.6k13 gold badges49 silver badges55 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 11

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/wikipedia/monS/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.

发布评论

评论列表(0)

  1. 暂无评论