leaflet本地加载arcgis切片

var origin = [-20037700, 33711400];//图层起点坐标  
var resolutions = [  
    8466.6836000338681, // Level 0  
    4233.341800016934, // Level 1  
    2116.670900008467, // Level 2  
    1058.3354500042335, // Level 3  
    529.16772500211675 // Level 4  
];  
var crs = new L.Proj.CRS(  
    '',   
    '+proj=cea +lon_0=0 +lat_ts=0 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs' , {  
        origin:  origin,  
        resolutions: resolutions  
    }  
);  
        var map = L.map('map',{  
    crs: crs,  
    continuousWorld: true,  
    worldCopyJump: false  
}).setView([23.39552, 113.308189], 0);  
var tileLayer = new L.TileLayer.TileLoad('http://localhost:8080/resources/china', {  
              maxZoom: resolutions.length - 1,  
              minZoom: 0,  
              continuousWorld: true  
          });  
tileLayer.addTo(map);  
/** 
 * 加载本地arcgis切片类 
 *  
 * @author ful 
 * @date 2014-09-03 
 * @copyright (c)  
 */  
  
/** 
 * 继承自TileLayer 
 * @param {Object} tomcat中映射该切片目录url 
 * @param {Object} options 
 */  
L.TileLayer.TileLoad = L.TileLayer.extend({  
    initialize: function (url, options) {  
        options = L.setOptions(this, options);  
        this.url = url + "/Layers/_alllayers/{z}/{x}/{y}.png";  
        L.TileLayer.prototype.initialize.call(this, this.url, options);  
    }  
});  
  
/** 
 * 重写TileLayer中获取切片url方法 
 * @param {Object} tilePoint 
 */  
L.TileLayer.prototype.getTileUrl = function(tilePoint) {  
    return L.Util.template(this._url, L.extend({  
        s: this._getSubdomain(tilePoint),  
        z: function() {  
            var value = tilePoint.z.toString(16);  
            return "L" + pad(value, 2);  
        },  
        x: function() {  
            var value = tilePoint.y.toString(16);  
            return "R" + pad(value, 8);  
        },  
        y: function() {  
            var value = tilePoint.x.toString(16);  
            return "C" + pad(value, 8);  
        }  
    }));  
};  
  
L.tileLayer.tileLoad = function(url, options){  
  return new L.TileLayer.TileLoad(url, options);  
};  
  
/** 
 * 高位补全方法 
 * @param {Object} 数字类型字符串 
 * @param {Object} 总位数,不足则高位补0 
 */  
var pad = function(numStr, n) {  
    var len = numStr.length;  
    while(len < n) {  
        numStr = "0" + numStr;  
        len++;    
    }  
    return numStr;  
};  

猜你喜欢

转载自www.cnblogs.com/lishanyang/p/9170352.html