Hi Robert,

I've created tile services in a national projection (British National grid, 
EPSG:27700, in my case) and accessed them from OpenLayers 2. The extent (inc. 
origin) of your map is specified in "maxExtent" within the options (2nd 
parameter) of the map constructor. Your "resolutions" are also passed in there 
and allow for progressive scales other than x2. These two items of information 
are sufficient to frame your tile source. I also use TMS for tile layers, but 
that might have just been because XYZ was added later and I never bothered 
adopting it.

Regards,
Warren

-----Original Message-----
From: Users [mailto:openlayers-users-boun...@lists.osgeo.org] On Behalf Of 
Robert Sanson
Sent: 30 December 2015 20:05
To: openlayers-users@lists.osgeo.org
Subject: [OpenLayers-Users] OpenLayers.Layer.XYZ - how to set origin?

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 
_______________________________________________
Users mailing list
us...@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/openlayers-users
_______________________________________________
Users mailing list
us...@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/openlayers-users

Reply via email to