How maptalks load ArcGIS tile layer

Recently ArcGIS need to load the tile layer, the official website demo running load ArcGIS tile layer is not a problem. If the URL ArcGIS tile layer is replaced by self-released ArcGIS map services, find out load, and services provided by ArcGIS API itself, but can be loaded up. Where is the problem in the end of it, so they try to write a custom extension method ArcGISTileLayer to load ArcGIS tile layer.

1, analysis of the ArcGIS API URL

Open your browser's Network

URL parameters are found by the dpi, bboxSR, imageSR, size, transparent, format, f, bbox composed of several parameters. More analysis will find several URL data, URL parameters dpi, bboxSR, imageSR, size, transparent, format, f these parameters are fixed. Only in bbox change. So, if we manually calculate bbox and stitching parameters can be achieved is not loaded ArcGIS layers of tile.

2, write the first version, the core code is as follows ( complete code )

var defaultArcParams = {
    dpi: '90',		
	bboxSR: '4326',
	imageSR: '4326',
	size: '512,512',
	transparent: true,
	format: 'png32',
	f:'image'
};
ArcGISTileLayer.prototype.getTileUrl = function getTileUrl(x, y, z) {
      var res = this.getSpatialReference().getResolution(z),
          tileConfig = this._getTileConfig(),
          tileExtent = tileConfig.getTilePrjExtent(x, y, res);

      var max = tileExtent.getMax(),
          min = tileExtent.getMin();
	  var bbox = [min.x, min.y, max.x, max.y].join(',');

	  var url = _TileLayer.prototype.getTileUrl.call(this, x, y, z);

      return url + getParamString(defaultArcParams, url, false) + '&bbox=' + bbox;
    };
复制代码

The next demo reform official website, found that indeed can be loaded successfully ArcGIS tile layer, while the hearts happy, the original load ArcGIS tile layer that simple. Immediately under their own map services published by ArcGIS trial and found not loaded. URL re-analyzed under the ArcGIS API, and ultimately found that only dpi, transparent, format, f these four parameters are the same, the other parameters bboxSR (EPSG), imageSR (EPSG), size (tile size), bbox (tileExtent) are It is to be calculated according to dynamic service.

3. Complete version

var defaultArcParams = {
    dpi: '90',		
	transparent: true,
	format: 'png32',
	f:'image'
};
ArcGISTileLayer.prototype.getTileUrl = function getTileUrl(x, y, z) {
      var res = this.getSpatialReference().getResolution(z),
          tileConfig = this._getTileConfig(),
          tileExtent = tileConfig.getTilePrjExtent(x, y, res);

      var max = tileExtent.getMax(),
          min = tileExtent.getMin();
	  var bbox = [min.x, min.y, max.x, max.y].join(',');
	  
	  var pro = this.getSpatialReference().getProjection()
	  var srid = pro.code.split(':').pop();
      this.arcParams['bboxSR'] = srid;
	  this.arcParams['imageSR'] = srid;
	  
	  var tileSize = this.getTileSize();
	  this.arcParams['size'] = tileSize.width + ',' + tileSize.height;

	  var url = _TileLayer.prototype.getTileUrl.call(this, x, y, z);

      return url + getParamString(this.arcParams, url, false) + '&bbox=' + bbox;
    };
复制代码

Test release of their own ArcGIS map services, successfully loaded.

Guess you like

Origin blog.csdn.net/weixin_34255793/article/details/91368576