I want to change tileSize from default 256 to 512. I am using WMS version 1.1.0 so i cannot add WIDTH and HEIGHT parameters directly to source.

There are some examples where custom tileGrid is created where we can specify tileSize. In my case it is working only if i know the resolutions

var tileGrid = new ol.tilegrid.TileGrid({
    tileSize :512

How to handle case when i use default resolutions (i do not specify them in view). Is there a way to retrieve the resolutions for projection before creating map? Or is there a better way to handle this kind of situation?

  • Welcome to gis.stackexchange! Please edit the title of your question to include enough information for future visitors to be able to find this thread when looking for the same problem.
    – underdark
    Commented Mar 12, 2016 at 16:03

2 Answers 2


Instead of your own answer, I'd suggest

var projection = ol.proj.get('EPSG:900913');
var tileGrid = ol.tilegrid.createXYZ({
  extent: projection.getExtent(),
  tileSize: 512

If you are using other projections than the ones built into OpenLayers, you need to use the projection's validity extent for the extent option that you pass to ol.tilegrid.createXYZ. You can find that extent e.g. under "projected bounds" on http://epsg.io/.

  • Thanks ahocevar. Tested for EPSG 900913 and 2180 (with projected bounds) and it is working. Clearly Your solution is better as it uses public method. Is there a way to retrieve the projected bounds using api?
    – gisit
    Commented Mar 13, 2016 at 23:02
  • There is. See the reprojection-by-code example, specifically github.com/openlayers/ol3/blob/v3.14.2/examples/….
    – ahocevar
    Commented Mar 15, 2016 at 15:05
  • 900913 is unofficial. (It's supposed to look kind of like "google.") The official code is 3857.
    – jpmc26
    Commented Oct 1, 2018 at 16:36

I found the solution. To generate tileGrid for projection i used method createForProjection (not documented in api) and then replaced tileSize attribute in the tileGrid:

var projection = ol.proj.get('EPSG:900913');
var tileGrid = ol.tilegrid.createForProjection(projection);
tileGrid.tileSize_ = 512;

It is working. I will test if it does not break anything else.

  • Don't hack the library internal, plz. If ol.tilegrid.createForProjection is not documented, it's because it's an OpenLayers 3 internal method. You should never use or modify directly it code. It's not something forgotten. For upgrading and making custom build for the library, it's clearly a bad practice. Just calculate resolutions looking at openlayers.org/en/master/examples/… for an example
    – ThomasG77
    Commented Mar 11, 2016 at 1:24
  • Can you confirm that the alogirtm for calculating resolutions in this link is universal for all projections?
    – gisit
    Commented Mar 11, 2016 at 8:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.