1

I want to fit my custom tiles at a certain region. For example let's say i have custom tiles for a certain country (example: USA) and I am using OSM or anything at all. How do i make sure that my tiles fit a certain extent. I tried putting in the extent but the layer does not load. Please help.

map = new Map({
      target: 'map',
      layers: [
        new TileLayer({
          source: new OSM({
            wrapX: false,
          }),
        }),
        new TileLayer({
          extent:[12679211,2560587,12703254,2544509],
          source: new XYZ({
            maxZoom: 16,
            projection: projection,
            tileSize: tileSize,
            tileUrlFunction: function(tileCoord) {
              console.log("--------------")
              console.log("before",tileCoord);
              console.log("after", " z = ",tileCoord[0] - 1," x = ",tileCoord[1]," y = ",(-tileCoord[2] - 1))
              return urlTemplate.replace('{z}', (tileCoord[0] - 1).toString())
                .replace('{x}', tileCoord[1].toString())
                .replace('{y}', (-tileCoord[2] - 1).toString());
            },
            wrapX: false
          })
        }),
      ],
      view: new View({
        center:  [12689317.435763245, 2552726.0298609314  ],
        zoom:13,
        minZoom: 0
      })
    });
  • 1
    What do you see in network debug? Are tiles loading? How is projection defined? – TomazicM Aug 2 '19 at 5:20
  • The tiles are not being loaded for this specific extent. However if i do this it works extent:[-13884991, 2870341, -7455066, 6338219]. It does not load the whole image only a certain part of it though but the extent works. – UzmakiAshim Aug 2 '19 at 5:40
  • You didn't answer: how is projection defined? – TomazicM Aug 2 '19 at 6:17
  • var projection = get('EPSG:3857'); – UzmakiAshim Aug 2 '19 at 7:10
  • Since EPSG 3857 covers the whole world, how are you tiles numbered, let's say four tiles at zoom level 1? – TomazicM Aug 2 '19 at 10:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.