OpenLayers加載本地ArcServer切片地圖

使用水經(jīng)注下載的地圖,切為ArcServer格式,在XYZ類的基礎(chǔ)上擴(kuò)展Grid。

/**

* @requires OpenLayers/Layer/Grid.js

*/

/**

* Class: OpenLayers.Layer.ArcTileXYZ

* The ArcTileXYZ class is designed to make it easier for people who have tiles

* arranged by a standard XYZ grid.

*

* Inherits from:

* ?-

*/

OpenLayers.Layer.ArcTileXYZ = OpenLayers.Class(OpenLayers.Layer.Grid, {

/**

* APIProperty: isBaseLayer

* Default is true, as this is designed to be a base tile source.

*/

isBaseLayer: true,

/**

* APIProperty: sphericalMercator

* Whether the tile extents should be set to the defaults for

* ? ?spherical mercator. Useful for things like OpenStreetMap.

* ? ?Default is false, except for the OSM subclass.

*/

sphericalMercator: false,

/**

* APIProperty: zoomOffset

* {Number} If your cache has more zoom levels than you want to provide

* ? ? access to with this layer, supply a zoomOffset. ?This zoom offset

* ? ? is added to the current map zoom level to determine the level

* ? ? for a requested tile. ?For example, if you supply a zoomOffset

* ? ? of 3, when the map is at the zoom 0, tiles will be requested from

* ? ? level 3 of your cache. ?Default is 0 (assumes cache level and map

* ? ? zoom are equivalent). ?Using is an alternative to

* ? ? setting if you only want to expose a subset

* ? ? of the server resolutions.

*/

zoomOffset: 0,

/**

* APIProperty: serverResolutions

* {Array} A list of all resolutions available on the server. ?Only set this

* ? ? property if the map resolutions differ from the server. This

* ? ? property serves two purposes. (a) can include

* ? ? resolutions that the server supports and that you don't want to

* ? ? provide with this layer; you can also look at , which is

* ? ? an alternative to for that specific purpose.

* ? ? (b) The map can work with resolutions that aren't supported by

* ? ? the server, i.e. that aren't in . When the

* ? ? map is displayed in such a resolution data for the closest

* ? ? server-supported resolution is loaded and the layer div is

* ? ? stretched as necessary.

*/

serverResolutions: null,

/**

* Constructor: OpenLayers.Layer.ArcTileXYZ

*

* Parameters:

* name - {String}

* url - {String}

* options - {Object} Hashtable of extra options to tag onto the layer

*/

initialize: function (name, url, options) {

if (options && options.sphericalMercator || this.sphericalMercator) {

options = OpenLayers.Util.extend({

projection: "EPSG:900913",

numZoomLevels: 19

}, options);

}

OpenLayers.Layer.Grid.prototype.initialize.apply(this, [

name || this.name, url || this.url, {}, options

]);

},

/**

* APIMethod: clone

* Create a clone of this layer

*

* Parameters:

* obj - {Object} Is this ever used?

*

* Returns:

* {} An exact clone of this OpenLayers.Layer.ArcTileXYZ

*/

clone: function (obj) {

if (obj == null) {

obj = new OpenLayers.Layer.ArcTileXYZ(this.name,

this.url,

this.getOptions());

}

//get all additions from superclasses

obj = OpenLayers.Layer.Grid.prototype.clone.apply(this, [obj]);

return obj;

},

/**

* Method: getURL

*

* Parameters:

* bounds - {}

*

* Returns:

* {String} A string with the layer's url and parameters and also the

* ? ? ? ? ?passed-in bounds and appropriate tile size specified as

* ? ? ? ? ?parameters

*/

getURL: function (bounds) {

var xyz = this.getXYZ(bounds);

var url = this.url;

if (OpenLayers.Util.isArray(url)) {

var s = '' + xyz.x + xyz.y + xyz.z;

url = this.selectUrl(s, url);

}

return OpenLayers.String.format(url, xyz);

},

/**

* Method: getXYZ

* Calculates x, y and z for the given bounds.

*

* Parameters:

* bounds - {}

*

* Returns:

* {Object} - an object with x, y and z properties.

*/

getXYZ: function (bounds) {

var res = this.getServerResolution();

var x = Math.round((bounds.left - this.maxExtent.left) /

(res * this.tileSize.w));

var y = Math.round((this.maxExtent.top - bounds.top) /

(res * this.tileSize.h));

var z = this.getServerZoom();

if (this.wrapDateLine) {

var limit = Math.pow(2, z);

x = ((x % limit) + limit) % limit;

}

return { 'x': this.getX(x), 'y': this.getY(y), 'z': this.getZ(z) };

},

/* APIMethod: setMap

* When the layer is added to a map, then we can fetch our origin

* ? ?(if we don't have one.)

*

* Parameters:

* map - {}

*/

setMap: function (map) {

OpenLayers.Layer.Grid.prototype.setMap.apply(this, arguments);

if (!this.tileOrigin) {

this.tileOrigin = new OpenLayers.LonLat(this.maxExtent.left,

this.maxExtent.bottom);

}

},

getZ: function (z) {

return this.format(z, 2, 10);

},

getY: function (y) {

if (y === -1) {

y = 0;

}

return this.format(y, 8, 16);

},

getX: function (x) {

return this.format(x, 8, 16);

},

format: function (num, n, s) {

var d = Array(n).join(0) + num.toString(s).toUpperCase();

return d.slice(-n);

},

CLASS_NAME: "OpenLayers.Layer.ArcTileXYZ"

});

使用:

var baseLayer = new OpenLayers.Layer.ArcTileXYZ('底圖',//name,url,options

'http://192.168.0.102:6068/Map/L${z}/R${y}/C${x}.png',

{

isBaseLayer: true,

visibility: true,

displayInLayerSwitcher: false

});

map.addLayer(baseLayer);


////////////////////////////

后來網(wǎng)上搜了一個(gè)類似的http://blog.csdn.net/devcopper/article/details/39479539

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容

  • 在itunesconnect后臺(tái)顯示的狀態(tài)是“Ready for sale”,即"可供銷售"。審核通過后,客戶即在...
    在這藍(lán)色天空下閱讀 13,344評(píng)論 2 7
  • 篆隸行草真, 五體無不精。 筆下龍蛇走, 氣勢貫長虹。 行云流水勢, 意會(huì)未可云。 遒勁力千鈞, 灑脫入勝景。 潤...
    曉月華夢閱讀 393評(píng)論 4 19
  • 今天休息,在中國日?qǐng)?bào)上讀到了一篇關(guān)于焦慮的文章。標(biāo)題是這樣的,你焦慮的根本原因是急于過標(biāo)配的人生,看到之后是深有同...
    愛聽音樂的貓閱讀 211評(píng)論 0 0