配置Openlayers中的縮放級別


文章來自:http://www.cnblogs.com/JenMinZhang/archive/2011/01/06/resolutions.html

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);
}}}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM