Mismatch between OpenLayers 5 and XYZ-layer on some zoom-levels












3















I have an image pyramid that I created with gdal2tiles. Then I displayed this layer on top of another map in OpenLayers 5 with the XYZ source.



On the map zoom levels 0-8 the XYZ layer is not aligning correctly with the underlying map, in the next zoom level it fits perfectly. (See the attached images below).



My guess is that I missed something in how to set up the OpenLayers layer but I can't figure out what.



Here is the OpenLayers part for the layer:



 private xyzlayer: TileLayer = new TileLayer({
opacity: 1,
extent: [613934.99711258523166, 6724227.18296865839511, 618936.50444324919954, 6729085.88076259661466],
source: new olXYZ({
maxZoom: 8,
projection: 'EPSG:3006',
url: 'http://localhost:10/georeferencerApp/georeferenced/gavle_test/{z}/{x}/{-y}.png',
tileGrid: new xyzTileGrid({
extent: [613934.997113, 6724227.18297, 618936.504443, 6729085.88076],
resolutions: [25.38836208458858, 12.69418104229429, 6.34709052114714, 3.17354526057357, 1.58677263028679, 0.79338631514339, 0.39669315757170, 0.19834657878585, 0.09917328939292]
})
})
});


This is the XML file from gdal2tiles:



<TileMap version="1.0.0" tilemapservice="http://tms.osgeo.org/1.0.0">
<Title>gavle_1954.tif</Title>
<Abstract></Abstract>
<SRS>EPSG:3006</SRS>
<BoundingBox minx="613934.99711258523166" miny="6724227.18296865839511" maxx="618936.50444324919954" maxy="6729085.88076259661466"/>
<Origin x="613934.99711258523166" y="6724227.18296865839511"/>
<TileFormat width="256" height="256" mime-type="image/png" extension="png"/>
<TileSets profile="raster">
<TileSet href="0" units-per-pixel="25.38836208458858" order="0"/>
<TileSet href="1" units-per-pixel="12.69418104229429" order="1"/>
<TileSet href="2" units-per-pixel="6.34709052114714" order="2"/>
<TileSet href="3" units-per-pixel="3.17354526057357" order="3"/>
<TileSet href="4" units-per-pixel="1.58677263028679" order="4"/>
<TileSet href="5" units-per-pixel="0.79338631514339" order="5"/>
<TileSet href="6" units-per-pixel="0.39669315757170" order="6"/>
<TileSet href="7" units-per-pixel="0.19834657878585" order="7"/>
<TileSet href="8" units-per-pixel="0.09917328939292" order="8"/>
</TileSets>
</TileMap>


And this is the gdal2tiles command:



gdal2tiles -p raster -z 0-8 -s EPSG:3006 gavle_1954.tif gavle_test


Could anyone give me a hint on what the problem might be?



Incorrect aligning on zoomlevel 0-8Correct aligning in next zoomlevel










share|improve this question









New contributor




Mårten Swärd is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

























    3















    I have an image pyramid that I created with gdal2tiles. Then I displayed this layer on top of another map in OpenLayers 5 with the XYZ source.



    On the map zoom levels 0-8 the XYZ layer is not aligning correctly with the underlying map, in the next zoom level it fits perfectly. (See the attached images below).



    My guess is that I missed something in how to set up the OpenLayers layer but I can't figure out what.



    Here is the OpenLayers part for the layer:



     private xyzlayer: TileLayer = new TileLayer({
    opacity: 1,
    extent: [613934.99711258523166, 6724227.18296865839511, 618936.50444324919954, 6729085.88076259661466],
    source: new olXYZ({
    maxZoom: 8,
    projection: 'EPSG:3006',
    url: 'http://localhost:10/georeferencerApp/georeferenced/gavle_test/{z}/{x}/{-y}.png',
    tileGrid: new xyzTileGrid({
    extent: [613934.997113, 6724227.18297, 618936.504443, 6729085.88076],
    resolutions: [25.38836208458858, 12.69418104229429, 6.34709052114714, 3.17354526057357, 1.58677263028679, 0.79338631514339, 0.39669315757170, 0.19834657878585, 0.09917328939292]
    })
    })
    });


    This is the XML file from gdal2tiles:



    <TileMap version="1.0.0" tilemapservice="http://tms.osgeo.org/1.0.0">
    <Title>gavle_1954.tif</Title>
    <Abstract></Abstract>
    <SRS>EPSG:3006</SRS>
    <BoundingBox minx="613934.99711258523166" miny="6724227.18296865839511" maxx="618936.50444324919954" maxy="6729085.88076259661466"/>
    <Origin x="613934.99711258523166" y="6724227.18296865839511"/>
    <TileFormat width="256" height="256" mime-type="image/png" extension="png"/>
    <TileSets profile="raster">
    <TileSet href="0" units-per-pixel="25.38836208458858" order="0"/>
    <TileSet href="1" units-per-pixel="12.69418104229429" order="1"/>
    <TileSet href="2" units-per-pixel="6.34709052114714" order="2"/>
    <TileSet href="3" units-per-pixel="3.17354526057357" order="3"/>
    <TileSet href="4" units-per-pixel="1.58677263028679" order="4"/>
    <TileSet href="5" units-per-pixel="0.79338631514339" order="5"/>
    <TileSet href="6" units-per-pixel="0.39669315757170" order="6"/>
    <TileSet href="7" units-per-pixel="0.19834657878585" order="7"/>
    <TileSet href="8" units-per-pixel="0.09917328939292" order="8"/>
    </TileSets>
    </TileMap>


    And this is the gdal2tiles command:



    gdal2tiles -p raster -z 0-8 -s EPSG:3006 gavle_1954.tif gavle_test


    Could anyone give me a hint on what the problem might be?



    Incorrect aligning on zoomlevel 0-8Correct aligning in next zoomlevel










    share|improve this question









    New contributor




    Mårten Swärd is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.























      3












      3








      3








      I have an image pyramid that I created with gdal2tiles. Then I displayed this layer on top of another map in OpenLayers 5 with the XYZ source.



      On the map zoom levels 0-8 the XYZ layer is not aligning correctly with the underlying map, in the next zoom level it fits perfectly. (See the attached images below).



      My guess is that I missed something in how to set up the OpenLayers layer but I can't figure out what.



      Here is the OpenLayers part for the layer:



       private xyzlayer: TileLayer = new TileLayer({
      opacity: 1,
      extent: [613934.99711258523166, 6724227.18296865839511, 618936.50444324919954, 6729085.88076259661466],
      source: new olXYZ({
      maxZoom: 8,
      projection: 'EPSG:3006',
      url: 'http://localhost:10/georeferencerApp/georeferenced/gavle_test/{z}/{x}/{-y}.png',
      tileGrid: new xyzTileGrid({
      extent: [613934.997113, 6724227.18297, 618936.504443, 6729085.88076],
      resolutions: [25.38836208458858, 12.69418104229429, 6.34709052114714, 3.17354526057357, 1.58677263028679, 0.79338631514339, 0.39669315757170, 0.19834657878585, 0.09917328939292]
      })
      })
      });


      This is the XML file from gdal2tiles:



      <TileMap version="1.0.0" tilemapservice="http://tms.osgeo.org/1.0.0">
      <Title>gavle_1954.tif</Title>
      <Abstract></Abstract>
      <SRS>EPSG:3006</SRS>
      <BoundingBox minx="613934.99711258523166" miny="6724227.18296865839511" maxx="618936.50444324919954" maxy="6729085.88076259661466"/>
      <Origin x="613934.99711258523166" y="6724227.18296865839511"/>
      <TileFormat width="256" height="256" mime-type="image/png" extension="png"/>
      <TileSets profile="raster">
      <TileSet href="0" units-per-pixel="25.38836208458858" order="0"/>
      <TileSet href="1" units-per-pixel="12.69418104229429" order="1"/>
      <TileSet href="2" units-per-pixel="6.34709052114714" order="2"/>
      <TileSet href="3" units-per-pixel="3.17354526057357" order="3"/>
      <TileSet href="4" units-per-pixel="1.58677263028679" order="4"/>
      <TileSet href="5" units-per-pixel="0.79338631514339" order="5"/>
      <TileSet href="6" units-per-pixel="0.39669315757170" order="6"/>
      <TileSet href="7" units-per-pixel="0.19834657878585" order="7"/>
      <TileSet href="8" units-per-pixel="0.09917328939292" order="8"/>
      </TileSets>
      </TileMap>


      And this is the gdal2tiles command:



      gdal2tiles -p raster -z 0-8 -s EPSG:3006 gavle_1954.tif gavle_test


      Could anyone give me a hint on what the problem might be?



      Incorrect aligning on zoomlevel 0-8Correct aligning in next zoomlevel










      share|improve this question









      New contributor




      Mårten Swärd is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.












      I have an image pyramid that I created with gdal2tiles. Then I displayed this layer on top of another map in OpenLayers 5 with the XYZ source.



      On the map zoom levels 0-8 the XYZ layer is not aligning correctly with the underlying map, in the next zoom level it fits perfectly. (See the attached images below).



      My guess is that I missed something in how to set up the OpenLayers layer but I can't figure out what.



      Here is the OpenLayers part for the layer:



       private xyzlayer: TileLayer = new TileLayer({
      opacity: 1,
      extent: [613934.99711258523166, 6724227.18296865839511, 618936.50444324919954, 6729085.88076259661466],
      source: new olXYZ({
      maxZoom: 8,
      projection: 'EPSG:3006',
      url: 'http://localhost:10/georeferencerApp/georeferenced/gavle_test/{z}/{x}/{-y}.png',
      tileGrid: new xyzTileGrid({
      extent: [613934.997113, 6724227.18297, 618936.504443, 6729085.88076],
      resolutions: [25.38836208458858, 12.69418104229429, 6.34709052114714, 3.17354526057357, 1.58677263028679, 0.79338631514339, 0.39669315757170, 0.19834657878585, 0.09917328939292]
      })
      })
      });


      This is the XML file from gdal2tiles:



      <TileMap version="1.0.0" tilemapservice="http://tms.osgeo.org/1.0.0">
      <Title>gavle_1954.tif</Title>
      <Abstract></Abstract>
      <SRS>EPSG:3006</SRS>
      <BoundingBox minx="613934.99711258523166" miny="6724227.18296865839511" maxx="618936.50444324919954" maxy="6729085.88076259661466"/>
      <Origin x="613934.99711258523166" y="6724227.18296865839511"/>
      <TileFormat width="256" height="256" mime-type="image/png" extension="png"/>
      <TileSets profile="raster">
      <TileSet href="0" units-per-pixel="25.38836208458858" order="0"/>
      <TileSet href="1" units-per-pixel="12.69418104229429" order="1"/>
      <TileSet href="2" units-per-pixel="6.34709052114714" order="2"/>
      <TileSet href="3" units-per-pixel="3.17354526057357" order="3"/>
      <TileSet href="4" units-per-pixel="1.58677263028679" order="4"/>
      <TileSet href="5" units-per-pixel="0.79338631514339" order="5"/>
      <TileSet href="6" units-per-pixel="0.39669315757170" order="6"/>
      <TileSet href="7" units-per-pixel="0.19834657878585" order="7"/>
      <TileSet href="8" units-per-pixel="0.09917328939292" order="8"/>
      </TileSets>
      </TileMap>


      And this is the gdal2tiles command:



      gdal2tiles -p raster -z 0-8 -s EPSG:3006 gavle_1954.tif gavle_test


      Could anyone give me a hint on what the problem might be?



      Incorrect aligning on zoomlevel 0-8Correct aligning in next zoomlevel







      openlayers gdal2tiles xyz






      share|improve this question









      New contributor




      Mårten Swärd is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question









      New contributor




      Mårten Swärd is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question








      edited 4 hours ago









      Taras

      2,0282624




      2,0282624






      New contributor




      Mårten Swärd is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 4 hours ago









      Mårten SwärdMårten Swärd

      183




      183




      New contributor




      Mårten Swärd is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      Mårten Swärd is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      Mårten Swärd is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















          1 Answer
          1






          active

          oldest

          votes


















          3














          It's not a standard XYZ grid, i.e. the largest tile 25.38836208458858 * 256 = 6499.42069365467648 is bigger than the extent 6729085.88076 - 6724227.18297 = 4858.69779 That wouldn't be a problem if the origin was top left, but yours is bottom left so using a {-y} placeholder in the url won't work correctly. Instead you will need to specify the origin and use a tile url function:



          source: new olXYZ({
          maxZoom: 8,
          projection: 'EPSG:3006',
          tileUrlFunction: function(tileCoord) {
          return 'http://localhost:10/georeferencerApp/georeferenced/gavle_test/' + tileCoord[0] + '/' + tileCoord[1] + '/' + tileCoord[2] + '.png';
          },
          tileGrid: new xyzTileGrid({
          extent: [613934.997113, 6724227.18297, 618936.504443, 6729085.88076],
          origin: [613934.997113, 6724227.18297],
          resolutions: [25.38836208458858, 12.69418104229429, 6.34709052114714, 3.17354526057357, 1.58677263028679, 0.79338631514339, 0.39669315757170, 0.19834657878585, 0.09917328939292]
          })
          })





          share|improve this answer























            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "79"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });






            Mårten Swärd is a new contributor. Be nice, and check out our Code of Conduct.










            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f309115%2fmismatch-between-openlayers-5-and-xyz-layer-on-some-zoom-levels%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            3














            It's not a standard XYZ grid, i.e. the largest tile 25.38836208458858 * 256 = 6499.42069365467648 is bigger than the extent 6729085.88076 - 6724227.18297 = 4858.69779 That wouldn't be a problem if the origin was top left, but yours is bottom left so using a {-y} placeholder in the url won't work correctly. Instead you will need to specify the origin and use a tile url function:



            source: new olXYZ({
            maxZoom: 8,
            projection: 'EPSG:3006',
            tileUrlFunction: function(tileCoord) {
            return 'http://localhost:10/georeferencerApp/georeferenced/gavle_test/' + tileCoord[0] + '/' + tileCoord[1] + '/' + tileCoord[2] + '.png';
            },
            tileGrid: new xyzTileGrid({
            extent: [613934.997113, 6724227.18297, 618936.504443, 6729085.88076],
            origin: [613934.997113, 6724227.18297],
            resolutions: [25.38836208458858, 12.69418104229429, 6.34709052114714, 3.17354526057357, 1.58677263028679, 0.79338631514339, 0.39669315757170, 0.19834657878585, 0.09917328939292]
            })
            })





            share|improve this answer




























              3














              It's not a standard XYZ grid, i.e. the largest tile 25.38836208458858 * 256 = 6499.42069365467648 is bigger than the extent 6729085.88076 - 6724227.18297 = 4858.69779 That wouldn't be a problem if the origin was top left, but yours is bottom left so using a {-y} placeholder in the url won't work correctly. Instead you will need to specify the origin and use a tile url function:



              source: new olXYZ({
              maxZoom: 8,
              projection: 'EPSG:3006',
              tileUrlFunction: function(tileCoord) {
              return 'http://localhost:10/georeferencerApp/georeferenced/gavle_test/' + tileCoord[0] + '/' + tileCoord[1] + '/' + tileCoord[2] + '.png';
              },
              tileGrid: new xyzTileGrid({
              extent: [613934.997113, 6724227.18297, 618936.504443, 6729085.88076],
              origin: [613934.997113, 6724227.18297],
              resolutions: [25.38836208458858, 12.69418104229429, 6.34709052114714, 3.17354526057357, 1.58677263028679, 0.79338631514339, 0.39669315757170, 0.19834657878585, 0.09917328939292]
              })
              })





              share|improve this answer


























                3












                3








                3







                It's not a standard XYZ grid, i.e. the largest tile 25.38836208458858 * 256 = 6499.42069365467648 is bigger than the extent 6729085.88076 - 6724227.18297 = 4858.69779 That wouldn't be a problem if the origin was top left, but yours is bottom left so using a {-y} placeholder in the url won't work correctly. Instead you will need to specify the origin and use a tile url function:



                source: new olXYZ({
                maxZoom: 8,
                projection: 'EPSG:3006',
                tileUrlFunction: function(tileCoord) {
                return 'http://localhost:10/georeferencerApp/georeferenced/gavle_test/' + tileCoord[0] + '/' + tileCoord[1] + '/' + tileCoord[2] + '.png';
                },
                tileGrid: new xyzTileGrid({
                extent: [613934.997113, 6724227.18297, 618936.504443, 6729085.88076],
                origin: [613934.997113, 6724227.18297],
                resolutions: [25.38836208458858, 12.69418104229429, 6.34709052114714, 3.17354526057357, 1.58677263028679, 0.79338631514339, 0.39669315757170, 0.19834657878585, 0.09917328939292]
                })
                })





                share|improve this answer













                It's not a standard XYZ grid, i.e. the largest tile 25.38836208458858 * 256 = 6499.42069365467648 is bigger than the extent 6729085.88076 - 6724227.18297 = 4858.69779 That wouldn't be a problem if the origin was top left, but yours is bottom left so using a {-y} placeholder in the url won't work correctly. Instead you will need to specify the origin and use a tile url function:



                source: new olXYZ({
                maxZoom: 8,
                projection: 'EPSG:3006',
                tileUrlFunction: function(tileCoord) {
                return 'http://localhost:10/georeferencerApp/georeferenced/gavle_test/' + tileCoord[0] + '/' + tileCoord[1] + '/' + tileCoord[2] + '.png';
                },
                tileGrid: new xyzTileGrid({
                extent: [613934.997113, 6724227.18297, 618936.504443, 6729085.88076],
                origin: [613934.997113, 6724227.18297],
                resolutions: [25.38836208458858, 12.69418104229429, 6.34709052114714, 3.17354526057357, 1.58677263028679, 0.79338631514339, 0.39669315757170, 0.19834657878585, 0.09917328939292]
                })
                })






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 2 hours ago









                MikeMike

                1,20636




                1,20636






















                    Mårten Swärd is a new contributor. Be nice, and check out our Code of Conduct.










                    draft saved

                    draft discarded


















                    Mårten Swärd is a new contributor. Be nice, and check out our Code of Conduct.













                    Mårten Swärd is a new contributor. Be nice, and check out our Code of Conduct.












                    Mårten Swärd is a new contributor. Be nice, and check out our Code of Conduct.
















                    Thanks for contributing an answer to Geographic Information Systems Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f309115%2fmismatch-between-openlayers-5-and-xyz-layer-on-some-zoom-levels%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Magento 2 controller redirect on button click in phtml file

                    Polycentropodidae