@@ -12629,69 +12629,153 @@ var TiledMapLayer = L.TileLayer.extend({
1262912629
1263012630 options: {
1263112631 url: null,
12632- serverType: SuperMap.ServerType.ISERVER,
12632+ //如果有layersID,则是在使用专题图
12633+ layersID: null,
12634+ //如果为 true,则将请求重定向到图片的真实地址;如果为 false,则响应体中是图片的字节流
12635+ redirect: false,
1263312636 transparent: null,
1263412637 cacheEnabled: null,
12635- layersID: null, //如果有layersID,则是在使用专题图
12638+ clipRegionEnabled: false,
12639+ //请求的地图的坐标参考系统。 如:prjCoordSys={"epsgCode":3857}。
12640+ prjCoordSys: null,
12641+ //切片的起始参考点,默认为地图范围的左上角。
12642+ origin: null,
12643+ //地图对象在同一范围内时,是否重叠显示
12644+ overlapDisplayed: true,
12645+ //避免地图对象压盖显示的过滤选项
12646+ overlapDisplayedOptions: null,
12647+ //切片版本名称,cacheEnabled 为 true 时有效。
12648+ tileversion: null,
12649+
1263612650 crs: null,
12651+ serverType: SuperMap.ServerType.ISERVER,
12652+
1263712653 attribution: 'Map Data <a href="http://support.supermap.com.cn/product/iServer.aspx">SuperMap iServer</a> with <a href="http://icltest.supermapol.com/">SuperMap iClient</a>'
1263812654 },
1263912655
1264012656 initialize: function (url, options) {
12641- this.options. url = url;
12657+ this.url = this._url = url;
1264212658 L.TileLayer.prototype.initialize.apply(this, arguments);
1264312659 L.setOptions(this, options);
12644- this._initParams();
1264512660 L.stamp(this);
1264612661 },
1264712662
1264812663 onAdd: function (map) {
1264912664 this._crs = this.options.crs || map.options.crs;
12665+ this._initLayerUrl();
1265012666 L.TileLayer.prototype.onAdd.call(this, map);
12651-
1265212667 },
1265312668
12669+
1265412670 getTileUrl: function (coords) {
12655- var x = coords.x, y = coords.y, zoom = coords.z;
12656- //使用ViewBounds出图
12657- var tileBounds = this._tileCoordsToBounds(coords),
12658- nw = this._crs.project(tileBounds.getNorthWest()),
12659- se = this._crs.project(tileBounds.getSouthEast());
12660- var tileUrl = this._layerUrl + "&viewBounds=" + "{\"leftBottom\" : {\"x\":" + nw.x + ",\"y\":" + se.y + "},\"rightTop\" : {\"x\":" + se.x + ",\"y\":" + nw.y + "}}";
12661-
12662- var crs = this._crs, scale = crs.scale(zoom);
12663- tileUrl += "&scale=" + scale;
12671+ var scale = this.getScale(coords);
12672+ var tileUrl = this._layerUrl + "&scale=" + scale + "&x=" + coords.x + "&y=" + coords.y;
1266412673 return tileUrl;
1266512674 },
1266612675
12667- _initParams: function () {
12668- var options = this.options;
12669- if (!options.url) {
12670- return;
12676+ setScales: function (scales) {
12677+ this.scales = scales || this.scales;
12678+ },
12679+
12680+ getScale: function (coords) {
12681+ var me = this, scale;
12682+ if (!coords) {
12683+ return me.scales;
1267112684 }
12672- this._layerUrl = this._initLayerUrl(options);
12685+ if (me.scales && me.scales[coords.z]) {
12686+ return me.scales[coords.z];
12687+ }
12688+ me.scales = me.scales || {};
12689+ scale = me.getDefaultScale(coords);
12690+ me.scales[coords.z] = scale;
12691+ return scale;
1267312692 },
1267412693
12675- _initLayerUrl: function (options) {
12694+ getDefaultScale: function (coords) {
12695+ var me = this, crs = me._crs;
12696+ var resolution;
12697+ if (crs.options && crs.options.resolutions) {
12698+ resolution = crs.options.resolutions[coords.z];
12699+ } else {
12700+ var tileBounds = me._tileCoordsToBounds(coords);
12701+ var ne = crs.project(tileBounds.getNorthEast());
12702+ var sw = crs.project(tileBounds.getSouthWest());
12703+ var tileSize = me.options.tileSize;
12704+ resolution = Math.max(
12705+ Math.abs(ne.x - sw.x) / tileSize,
12706+ Math.abs(ne.y - sw.y) / tileSize
12707+ );
12708+ }
1267612709
12677- var layerUrl = options.url + "/image.png?redirect=false";
12710+ var mapUnit = SuperMap.Unit.METER;
12711+ if (crs.code && crs.code.indexOf("4326") > -1) {
12712+ mapUnit = SuperMap.Unit.DEGREE;
12713+ }
12714+ return L.Util.resolutionToScale(resolution, 96, mapUnit);
12715+ },
1267812716
12717+ _initLayerUrl: function () {
12718+ var me = this;
12719+ var layerUrl = me.url + "/tileImage.png?";
12720+ layerUrl += me._initAllRequestParams().join('&');
1267912721 layerUrl = this._appendCredential(layerUrl);
12722+ this._layerUrl = layerUrl;
12723+ },
12724+
12725+ _initAllRequestParams: function () {
12726+ var me = this, options = me.options || {}, params = [];
12727+
12728+ var tileSize = this.options.tileSize;
12729+ params.push("width=" + tileSize);
12730+ params.push("height=" + tileSize);
12731+
12732+ var redirect = (options.redirect === true) ? options.redirect : false;
12733+ params.push("redirect=" + redirect);
12734+
12735+ var transparent = (options.transparent === true) ? options.transparent : false;
12736+ params.push("transparent=" + transparent);
12737+
12738+ var cacheEnabled = (options.cacheEnabled === false) ? options.cacheEnabled : true;
12739+ params.push("cacheEnabled=" + cacheEnabled);
12740+
12741+ if (options.prjCoordSys) {
12742+ params.push("prjCoordSys=" + JSON.stringify(options.prjCoordSys));
12743+ }
1268012744
1268112745 if (options.layersID) {
12682- layerUrl += "& layersID=" + options.layersID;
12746+ params.push(" layersID=" + options.layersID) ;
1268312747 }
1268412748
12685- var transparent = (options.transparent) ? options.transparent : false;
12686- layerUrl += "&transparent=" + transparent;
12749+ if (options.clipRegionEnabled && options.clipRegion instanceof L.Path) {
12750+ options.clipRegion = L.Util.toSuperMapGeometry(options.clipRegion.toGeoJSON());
12751+ options.clipRegion = SuperMap.Util.toJSON(SuperMap.REST.ServerGeometry.fromGeometry(options.clipRegion));
12752+ params.push("clipRegionEnabled=" + options.clipRegionEnabled);
12753+ params.push("clipRegion=" + JSON.stringify(options.clipRegion));
12754+ }
1268712755
12688- var cacheEnabled = (options.cacheEnabled) ? options.cacheEnabled : true;
12689- layerUrl += "&cacheEnabled=" + cacheEnabled;
12756+ //切片的起始参考点,默认为地图范围的左上角。
12757+ if (options.origin) {
12758+ var tileOrigin = options.origin;
12759+ if (L.Util.isArray(options.origin)) {
12760+ tileOrigin = L.latLng(options.origin);
12761+ }
12762+ params.push("origin={\"x\":" + tileOrigin.lng + "," + "\"y\":" + tileOrigin.lat + "}");
12763+ }
1269012764
12691- var tileSize = this.options.tileSize;
12692- layerUrl += "&width=" + tileSize + "&height=" + tileSize;
12765+ if (options.overlapDisplayed === false) {
12766+ params.push("overlapDisplayed=false");
12767+ if (options.overlapDisplayedOptions) {
12768+ params.push("overlapDisplayedOptions=" + me.overlapDisplayedOptions.toString());
12769+ }
12770+ } else {
12771+ params.push("overlapDisplayed=true");
12772+ }
12773+
12774+ if (options.cacheEnabled === true && options.tileversion) {
12775+ params.push("tileversion=" + options.tileversion)
12776+ }
1269312777
12694- return layerUrl ;
12778+ return params ;
1269512779 },
1269612780
1269712781 //追加token或key
@@ -13981,7 +14065,7 @@ var TileVectorLayer = L.VectorGrid.extend({
1398114065 }
1398214066
1398314067 var mapUnit = SuperMap.Unit.METER;
13984- if (crs.code.indexOf("4326") > -1) {
14068+ if (crs.code && crs.code .indexOf("4326") > -1) {
1398514069 mapUnit = SuperMap.Unit.DEGREE;
1398614070 }
1398714071 return L.Util.resolutionToScale(resolution, 96, mapUnit);
0 commit comments