配置Openlayers中的缩放级别

OpenLayers Map可以在不同的比例尺或解析度下显示他的每一个layer
map对象含有缩放级别的引用,即ZoomLevels,而且允许他的每一个layer去自定义他们自己的缩放级别,使之看起来合适
可以通过在构造函数中设置options属性来配置openlayers layer的缩放级别

== 正常图层==
对于基于openlayers.layer的正常layer,和能够在任何解析度下显示的layer,存在多种不同的方式去配置缩放级别和他们各自的比例尺和解析度

“解析度数组”:
要是转化缩放级别成为解析度,需要一个{{{resolutions}}}数组,他是这个图层所支持的不同解析度的列表,缩放级别就仅仅是一个解析度数组的索引,解析度数组始于0终于缩放级别-1

比如:
一个图层的解析度为[a,b,c],那么缩放级别的0就是a ,1就是b。。。


=== 配置解析度数组的方式 ===

可选项:
{{{scales}}} - ''Array'' -- 预先设置比例尺值的数组
{{{resolutions}}} - ''Array'' -- 预先设置解析度值的数组
{{{minScale}}} - ''float'' --layer能够显示的最小比例尺
{{{maxScale}}} - ''float'' --layer能够显示的最大比例尺
{{{maxResolution}}} - ''float'' --layer能够显示的最大解析度
{{{minResolution}}} - ''float'' -- layer能够显示的最小解析度
{{{minExtent}}} - ''!OpenLayers.Bounds'' --layer能显示出的最小范围
{{{maxExtent}}} - ''!OpenLayers.Bounds'' -- layer能显示出的最大范围
{{{numZoomLevels}}} - ''int'' -- 缩放级别的总数
{{{units}}} - ''String'' - layer显示的单位,作用于比例尺-解析度换算

Example Declarations:
{{{
    var options = { scales: [50000000, 30000000, 10000000, 5000000],
                    resolutions: [1.40625,0.703125,0.3515625,0.17578125,0.087890625,0.0439453125],
                    minScale: 50000000,
                    maxResolution: "auto",
                    maxExtent: new OpenLayers.Bounds(-180, -90, 180, 90),
                    maxResolution: 0.17578125,
                    maxScale: 10000000,
                    minResolution: "auto",
                    minExtent: new OpenLayers.Bounds(-1, -1, 1, 1),
                    minResolution: 0.0439453125,
                    numZoomLevels: 5,
                    units: "degrees"
                  };
    map = new OpenLayers.Map( $('map') , options);
}}}


显然所有的配置项不能在一次设置中全都用上,因为他们可能相互冲突,他们会按照下面的优先级起作用:

[A]【预设的缩放级别列表】缩放级别由预先设置的比例尺或解析度决定

{{{scales}}} -解析度的数组由这些比例尺直接转化而来
{{{resolutions}}} - 解析度数组直接从初始化函数的option参数中带来
Examples:
{{{
    var options = { scales: [50000000, 30000000, 10000000, 5000000] };
    map = new OpenLayers.Map( $('map') , options);
}}}

{{{
    var options = { resolutions: [1.40625,0.703125,0.3515625,0.17578125,0.087890625,0.0439453125] };
    map = new OpenLayers.Map( $('map') , options);
}}}

* '''maxResolution and numZoomLevels''' - ''!ZoomLevels are determined based on a maximum resolution and the number of desired !ZoomLevels''


[B]【最大解析度 &缩放级别的总数】缩放级别在最大解析度和缩放级别的总数上被决定
B1 最大解析度的确定
{{{minScale}}} --解析度的值从比例尺由单位{{{units}}}转化来
{{{maxExtent}}} AND {{{maxResolution == "auto"}}} --解析度由地图的div尺寸和maxExtent属性计算而来。若maxExtent属性未指定,默认从map继承,即全世界
{{{maxResolution}}}--解析度的值直接从layer的options参数中带来,若没指定,则默认为从map的options中带来
B2 缩放级别的总数确定
    B2_a基于最大和最小解析度的比值来计算--确定最小解析度:
{{{maxScale}}} --解析度的值从比例尺由单位{{{units}}}转化来
{{{minExtent}}} AND {{{minResolution == "auto"}}}--解析度的值基于地图div尺寸和minExtent属性来计算。minExtent属性必须被指定,默认不从map继承
{{{minResolution}}} --解析度的值从layer指定的option参数中直接带来,若没指定,最小解析度保持为空,缩放级别数直接接受
    B2_b {{{numZoomLevels}}}缩放级别数直接从layer指定的option参数带来,若没有指定默认从map的option带来

Examples:

||maxResolution||Converted from minScale using specified units||
||numZoomLevels||Default from map||
{{{
    var options = { minScale: 50000000,
                    units: "degrees"
                  };
    map = new OpenLayers.Map( $('map') , options);
}}}
[[BR]]

||maxResolution||Calculated based on div size and default maxExtent from map||基于div的尺寸和地图最大范围计算
||numZoomLevels||Calculated using ratio of maxResolution/minResolution||用最大最小分辨率的比值计算
{{{
    var options = { maxResolution: "auto",
                    maxExtent: new OpenLayers.Bounds(-180, -90, 180, 90),
                    minResolution: 0.0439453125
                  };
    map = new OpenLayers.Map( $('map') , options);
}}}
[[BR]]

||maxResolution||Specified||
||numZoomLevels||Specified||
{{{
    var options = { maxResolution: 0.17578125,
                    numZoomLevels: 15
                  };
            map = new OpenLayers.Map( $('map') , options);
}}}
[[BR]]

||maxResolution||Default from map||
||numZoomLevels||Converted maxScale (using default units from map) to minResolution, then uses ratio of maxResolution/minResolution to calculate numZoomLevels||
{{{
    var options = { maxScale: 10000000 };
    map = new OpenLayers.Map( $('map') , options);
}}}
[[BR]]

||maxResolution||Specified||
||numZoomLevels||Calculated minResolution based on div size and default minExtent from map, then uses ratio of maxResolution/minResolution to calculate numZoomLevels||
{{{
    var options = { maxResolution: 0.17578125,
                    minResolution: "auto",
                    minExtent: new OpenLayers.Bounds(-1, -1, 1, 1),
                  };
    map = new OpenLayers.Map( $('map') , options);
}}}

posted @ 2011-01-06 10:17  JenMinZhang  阅读(2728)  评论(0编辑  收藏  举报