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

 最后赋一段extend代码

       // 扩展加载ArcServer本地缓存的服务
        L.TileLayer.ArcServerTileLoad = L.TileLayer.extend({
            getTileUrl: function(tilePoint) {
                var oo = "00000000";
                var xx = tilePoint.x.toString(16);
                xx = "C" + oo.substring(0, 8 - xx.length) + xx;
                //var yy = (tilePoint.y - Math.pow(2, tilePoint.z - 2)).toString(16); //这里减去偏移值
                var yy = tilePoint.y.toString(16);
                yy = "R" + oo.substring(0, 8 - yy.length) + yy;

                //z如果小于10的时候处理下
                if(tilePoint.z.toString().length == 1) {
                    tilePoint.z = '0' + tilePoint.z.toString();
                }
                return L.Util.template(this._url, L.extend({
                    s: this._getSubdomain(tilePoint),
                    z: "L" + tilePoint.z,
                    x: xx,
                    y: yy
                }, this.options));
            }
        });


        L.tileLayer.arcServerTileLoad = function(url, options){
            return new L.TileLayer.ArcServerTileLoad(url, options);
        };
        //return this.baseLayer = L.tileLayer.arcServerTileLoad(url);

 

posted @ 2018-06-11 22:34  羊大葱  阅读(1590)  评论(2编辑  收藏  举报