User:Kannix/mbtiles

From OpenStreetMap Wiki
Jump to navigation Jump to search

transparent way to flip y-coordinate in openlayers.layer.XYZ

map.addLayer (new OpenLayers.Layer.XYZ("CEMT-test",
      ['http://tiles.grade.de/cemt-mbt/mbtiles/cemt/${z}/${x}/${y}.png'],
      { visibility      : false,
        transitionEffect: "resize",
        isBaseLayer     : false,
        getXYZ          : mbtilesXYZ
       }));
function mbtilesXYZ(bounds) {
       var res = this.map.getResolution();
       var x = Math.round((bounds.left - this.maxExtent.left) / (res * this.tileSize.w));
       var y = Math.round((bounds.bottom - this.tileOrigin.lat) / (res * this.tileSize.h));
       var z = this.map.getZoom();
       return {'x': x, 'y': y, 'z': z};
     }

Math to flip y-coords:

coord.row = Math.pow(2, coord.zoom) - coord.row - 1;