Add Bing Tile Layer which uses quadkey

132
0
2 weeks ago
François-XavierHays
New Contributor

Hi,

 

I am trying to add a web tile service that was made through Bing tiles and using the quadkey system. I have a tile API which works in QGIS with the {q} parameter instead of {x}/{y}/{z}.

I have created a custom BaseTileLayer as below, but doesn't seem to work properly:

 

let quadKey= function (x, y, z) {
  var quadKey = [];
  for (var i = z; i > 0; i--) {
      var digit = '0';
      var mask = 1 << (i - 1);
      if ((x & mask) != 0) {
          digit++;
      }
      if ((y & mask) != 0) {
          digit++;
          digit++;
      }
      quadKey.push(digit);
  }
  return quadKey.join('');
};

let MyCustomTileLayer = BaseTileLayer.createSubclass({
  // properties of the custom tile layer
  properties: {
    urlTemplate: null,
  },
 // override getTileUrl()
 // generate the tile url for a given level, row and column
 getTileUrl: function (level, row, col) {
 
   return this.urlTemplate.replace("{q}", quadKey(col,row,level));
 }
});

const  NewLayer = new MyCustomTileLayer({
  urlTemplate: "****/{q}?apikey=****"
});
 
 

Would you have any idea how to proceed?

 

Thanks

0 Kudos
0 Replies