[OpenLayers-Users] OpenLayers.Layer.XYZ - how to set origin?
Robert Sanson
Robert.Sanson at asurequality.com
Wed Dec 30 12:05:00 PST 2015
Dear OpenLayers Users
I am trying to connect to a custom tile cache, using OpenLayers.Layer.XYZ
The projection used is EPSG:2193 (New Zealand Transverse Mercator) and the tileOrigin for this service is -1000000, 10000000 (top left)
The extents of the imagery are: [827933.23, 3729820.29, 3195373.59, 7039943.58]
How do I set the tileOrigin on the layer? Is it based on the map maxExtent?
Looking at XYZ.js it has:
/**
* Method: getXYZ
* Calculates x, y and z for the given bounds.
*
* Parameters:
* bounds - {<OpenLayers.Bounds>}
*
* Returns:
* {Object} - an object with x, y and z properties.
*/
getXYZ: function(bounds) {
var res = this.getServerResolution();
var x = Math.round((bounds.left - this.maxExtent.left) /
(res * this.tileSize.w));
var y = Math.round((this.maxExtent.top - bounds.top) /
(res * this.tileSize.h));
var z = this.getServerZoom();
if (this.wrapDateLine) {
var limit = Math.pow(2, z);
x = ((x % limit) + limit) % limit;
}
return {'x': x, 'y': y, 'z': z};
},
/* APIMethod: setMap
* When the layer is added to a map, then we can fetch our origin
* (if we don't have one.)
*
* Parameters:
* map - {<OpenLayers.Map>}
*/
setMap: function(map) {
OpenLayers.Layer.Grid.prototype.setMap.apply(this, arguments);
if (!this.tileOrigin) {
this.tileOrigin = new OpenLayers.LonLat(this.maxExtent.left,
this.maxExtent.bottom);
}
},
Many thanks,
Robert Sanson
More information about the Users
mailing list