Any idea to get center coordinate in each tile from basemap?

1100
5
07-21-2017 04:14 AM
AyakoSUZUKI
New Contributor III

I want to get center coordinate in each tile from basemap.

I am using JS API and I can get origin, level, row and colum.

So I think I can get center point by using math calculation.

But I do not have any idea...

I attached an image to show what I want to know.

Any help would be great!

0 Kudos
5 Replies
ThomasSolow
Occasional Contributor III

Here's a sample that draws each tile's extent as the tiles update (ie as you zoom in and out)

JS Bin - Collaborative JavaScript Debugging 

You could draw the center of each extent rather than the extent itself.

AyakoSUZUKI
New Contributor III

This is a great idea!

However, I need to get center point when I create basemap.

I am tyring to create custom basemap layer by extending TiledMapServiceLayer class.

Because the tile service uses different schema, I concluded I need center point to retrieve tiles.

The snippet below is what I've done so far.

var CustomLayer = declare([TiledMapServiceLayer], {
  constructor: function(){
    this.spatialReference = new SpatialReference(...);
    this.initialExtent = (this.fullExtent = new Extent(...));

    this.tileInfo = new TileInfo({
      rows: 256,
      cols: 256,
      dpi: 96,
      format: "png",
      compressionQuality: 90,
      origin: {x: -2.0037508342787E7, y: 2.0037508342787E7},
      spatialReference: {wkid: 102100},
      lods: [
        { level: 0, resolution: 156543.03392800014, scale: 5.91657527591555E8 },
        { level: 1, resolution: 78271.51696399994, scale: 2.95828763795777E8 },
        .....
      ]
    });

    this.loaded = true;
    this.onLoad(this);
  },

  getTileUrl: function(level, row, col) {
    /* need to get center point in each tile to create request url*/
    return url;
  }
});‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
ThomasSolow
Occasional Contributor III

Hmm, that's a harder problem.  Thinking about it, there should be a way to figure out of the center of each tile if you know the row, column, origin, and resolution.

Speaking generally, I would think that the x, y would be (col + .5) * resolution, (row + .5) * resolution (assuming the tile coordinates are 0 based).  But I'm unsure how the "tile grid" is oriented compared to the web mercator x, y axis.  Maybe you can figure this out based on the origin that is passed into the TileInfo.

I'll take a look at the source code and see if I can find an example of this being done.

0 Kudos
anweshponugumati2
New Contributor

Hi Any luck with solution for this? 

0 Kudos
JohnGrayson
Esri Regular Contributor

If using BaseTileLayer you can use the getTileBound() method.

0 Kudos