Select to view content in your preferred language

Bug: MapImageLayer at International Dateline

251
1
05-09-2024 05:45 PM
JoelBennett
MVP Regular Contributor

We have a basic map service published to ArcGIS Server which displays some polygons.  Some of those polygons cross the International Dateline (ID), but they're getting clipped like shown:

id1.png

On the client, this is a basic MapImageLayer.  I've noticed when the view crosses the ID, the SDK shifts the central meridian of the extent that gets sent to the export operation of the map service.  For the image above, the query parameters for the export operation are shown:

 id2.png

As can be seen, the bbox parameters are shifted from the extent of the View, and the Central_Meridian values of the spatial references are set to a value other than the default.  I don't really understand the inner workings of all that, but it nevertheless appears to be what's causing the problem.

I've come up with a hack to get this showing the expected images like so:

id3.png

This is done by overriding the createExportImageParameters method of MapImageLayer.  I use Extent.normalize to determine if the image extent crosses the ID, and if it does, I expand the left piece by the width of the right piece, and use that for bbox instead:

 

var createExportImageParameters = MapImageLayer.prototype.createExportImageParameters;

MapImageLayer.prototype.createExportImageParameters = function(extent, width, height, options) {
	var exportImageParameters = createExportImageParameters.apply(this, arguments);

	if ((exportImageParameters.bbox) && (this.spatialReference?.isWrappable)) {
		var extents = extent.normalize();

		if (extents.length == 2) {
			var ext1 = extents[0];

			exportImageParameters.bbox = ext1.xmin.toString() + "," + ext1.ymin.toString() + "," + (ext1.xmax + extents[1].width).toString() + "," + ext1.ymax.toString();
			exportImageParameters.bboxSR = JSON.stringify(extent.spatialReference.toJSON());
			exportImageParameters.imageSR = exportImageParameters.bboxSR;
		}
	}

	return exportImageParameters;
};

 

 

Therefore, the query parameters for the proper image look like this:

id4.png

 

It seems to be working fine, but could we get this fixed in the SDK itself?  Also, if there's a better temporary fix between now and then, I'd be grateful to know as well.

This occurred using version 4.29, but I don't know if it occurs in previous versions or not.  Also note, we observed the same behavior when loading the individual layers in as FeatureLayers, but I didn't try tracking that one down.

0 Kudos
1 Reply
JoelBennett
MVP Regular Contributor

For the very few people interested (if any at all), this occurs in 3.x as well.  The following hack to the _onExtentChangeHandler function of DynamicMapServiceLayer appears to do the job:

 

var _onExtentChangeHandler = DynamicMapServiceLayer.prototype._onExtentChangeHandler;

DynamicMapServiceLayer.prototype._onExtentChangeHandler = function(a, b, c) {
	if ((a) && (a.declaredClass == "esri.geometry.Extent")) {
		var extents = a.normalize();

		if (extents.length == 2) {
			var ext1 = extents[0];
			var ext2 = new Extent(ext1.xmin, ext1.ymin, ext1.xmax + extents[1].getWidth(), ext1.ymax, ext1.spatialReference);
			ext2._normalize = function() { return this; };

			_onExtentChangeHandler.call(this, ext2, b, c);

			return;
		}
	}

	_onExtentChangeHandler.apply(this, arguments);
};

 

 Note, only tested with 3.46...

0 Kudos