日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

扩展 OpenLayers.Layer.WMS 为自定义的瓦片浏览服务

發(fā)布時間:2025/4/16 49 豆豆
生活随笔 收集整理的這篇文章主要介紹了 扩展 OpenLayers.Layer.WMS 为自定义的瓦片浏览服务 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

WMS 是OGC制定的標(biāo)準(zhǔn) WEB GIS 協(xié)議,現(xiàn)在眾多的圖形提供商都提供了自己的WEB圖形服務(wù),例如:ArcIMS、GoogleMaps、KaMap等等、要使用這些服務(wù)并制作自己的WEB客戶端,使用 OpenLayers 是很方便的事情,其中 WMS 是比較通用的協(xié)議,尤其適合服務(wù)器端矢量圖形的生成,但是在我們自己的項目中發(fā)現(xiàn)由于WMS每次發(fā)送給服務(wù)器的都是幾何坐標(biāo)的格式化字符串來表達視野,這導(dǎo)致服務(wù)器端在提供瓦片時無法很好的進行高效的服務(wù),幾乎總是需要對瓦片進行拼接和剪裁,通過分析 GOOGLE 和 TMS 協(xié)議,發(fā)現(xiàn)很多服務(wù)都不采用幾何坐標(biāo)的字符串來表達視野,而是直接提供瓦片的行列號,這樣服務(wù)器端甚至可以直接使用一個簡單的HTTP服務(wù)器就可以了,基于以上考慮決定擴展OpenLayers來提供一個自己的瓦片服務(wù)的客戶端;

原理很簡單,就是在構(gòu)造 WMS請求的URL時,采用自己的方式進行構(gòu)造,代碼如下:

?

1 /**
2 * Class: ShineEnergy.Layer.TileImage
3 *
4 * Inherits from:
5 * - <OpenLayers.Layer.WMS>
6 */
7 ShineEnergy.Layer.TileImage = OpenLayers.Class(OpenLayers.Layer.WMS, {
8
9 /**
10 * Constructor: ShineEnergy.Layer.TileImage
11 *
12 * Parameters:
13 * name - {String} A name for the layer
14 * url - {String} Base url for the TileImage
15 * params - {Object} An object with key/value pairs representing the
16 * GetMap query string parameters and parameter values.
17 * options - {Object} Hashtable of extra options to tag onto the layer
18 */
19 initialize: function(name, url, params, options) {
20 OpenLayers.Layer.WMS.prototype.initialize.apply(this, arguments);
21 },
22
23 /**
24 * APIMethod:destroy
25 */
26 destroy: function() {
27 // for now, nothing special to do here.
28 ? OpenLayers.Layer.WMS.prototype.destroy.apply(this, arguments);
29 },
30
31 /**
32 * APIMethod: clone
33 *
34 * Parameters:
35 * obj - {Object}
36 *
37 * Returns:
38 * {<ShineEnergy.Layer.TileImage>} An exact clone of this <ShineEnergy.Layer.TileImage>
39 */
40 clone: function (obj) {
41
42 if (obj == null) {
43 obj = new ShineEnergy.Layer.TileImage(this.name,
44 this.url,
45 this.options);
46 }
47
48 //get all additions from superclasses
49 ? obj = OpenLayers.Layer.WMS.prototype.clone.apply(this, [obj]);
50
51 // copy/set any non-init, non-simple values here
52 ?
53 return obj;
54 },
55
56 /**
57 * Method: getURL
58 *
59 * Parameters:
60 * bounds - {<OpenLayers.Bounds>}
61 *
62 * Returns:
63 * {String} A string with the layer's url and parameters and also the
64 * passed-in bounds and appropriate tile size specified as
65 * parameters
66 */
67 getURL: function (bounds) {
68 bounds = this.adjustBounds(bounds);
69 var res = this.map.getResolution();
70 var tileOriginY = this.options.maxExtent.top;
71 var tileOriginX = this.options.maxExtent.left;
72 var x = Math.round((bounds.left - tileOriginX) / (res * this.tileSize.w));
73 var y = Math.round((tileOriginY - bounds.bottom) / (res * this.tileSize.h));
74 var z = this.map.getZoom();
75 var path = "?LAYER=" + this.params.LAYERS + "&X=" + x + "&Y=" + y + "&Z=" + z + "&S=Map";
76 var url = this.url;
77 if (url instanceof Array) {
78 url = this.selectUrl(path, url);
79 }
80 return url + path;
81 },
82
83 CLASS_NAME: "ShineEnergy.Layer.TileImage"
84 });
85 ?

?經(jīng)過如上簡單的進行擴展,就可以使用實現(xiàn)自定義的 WEB GIS 協(xié)議,服務(wù)器端只需要根據(jù) LAYER/X/Y/Z參數(shù)可以確定唯一的一張瓦片圖片,返回給客戶端就可以了,同時也方便服務(wù)器端采用緩存優(yōu)化處理;

在上面的例子中還有一個參數(shù)“S”,這個參數(shù)是備用參數(shù),你也可以當(dāng)做是一個展示如何增加自定義參數(shù)的例子來修改,例如增加控制客戶端的緩存行為的功能就可以根據(jù)時間產(chǎn)生不同的參數(shù)來實現(xiàn);

最后補充一點,WMS協(xié)議在根據(jù)視野填充瓦片的時候,是根據(jù)左下角的地理坐標(biāo)開始進行填充的,而ARCGIS等工具則是根據(jù)左上角進行行列號進行編排的,所以要想能夠和其他的圖層完全配準(zhǔn),那么必須根據(jù)DPI和比例尺計算出一個確定的視野高度,這個高度要求能夠正好在最大的視野情況下正好有整數(shù)個瓦片進行平鋪;

轉(zhuǎn)載于:https://www.cnblogs.com/WonKerr/archive/2010/01/22/OpenLayers_Layer_TileImage.html

總結(jié)

以上是生活随笔為你收集整理的扩展 OpenLayers.Layer.WMS 为自定义的瓦片浏览服务的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。