Skip to content

Instantly share code, notes, and snippets.

@pborissow
Last active July 23, 2020 14:07
Show Gist options
  • Save pborissow/11252093ed3647327b9d60e423b2ceb2 to your computer and use it in GitHub Desktop.
Save pborissow/11252093ed3647327b9d60e423b2ceb2 to your computer and use it in GitHub Desktop.
OpenLayers Stuff

OpenLayers Notes

  //**************************************************************************
  //** getTiles
  //**************************************************************************
  /** Demostrates how to iterate through all the tiles in a layer
   */
    var getTiles = function(layer){
        var renderer = layer.getRenderer();
        var tiles = renderer.renderedTiles;
        for (var i=0; i<tiles.length; i++){
            var tile = tiles[i];
            var z = tile.tileCoord[0];
            var x = tile.tileCoord[1];
            var y = tile.tileCoord[2];
            var img = tile.getImage();

            //img.src = canvas.toDataURL('image/png');
        }
    };

  //**************************************************************************
  //** getOverlappingTile
  //**************************************************************************
  /** Demostrates how to find a tile that sits above or below the given tile
   */
    var getOverlappingTile = function(tile, layer, targetLayer){
        var renderer = layer.getRenderer();
        var pixelRatio = renderer.renderedPixelRatio;
        var projection = renderer.renderedProjection;
        var tileSource = targetLayer.getSource();
        var z = tile.tileCoord[0];
        var x = tile.tileCoord[1];
        var y = tile.tileCoord[2];
        return tileSource.getTile(z, x, y, pixelRatio, projection);
    };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment