[OSM-newbies] Converting lat/lon to pixel within a tile

root john at mckerrell.net
Fri May 2 14:38:58 BST 2008


Hi

Sorry I probably wasn't very clear in my previous email as I rushed it a
bit, it was more intended to give you an idea how to work it out. I
haven't loaded the tile in photoshop or anything but looking at your
calculations and comparing them to a map tile, they do appear to have
worked. The point on the tile that is at 142,11 pixels (from the top
left) appears to be the point that you want to center on. How you center
it will depend partly on how you're displaying, but perhaps moving the
tile or the canvas as follows will do it:

(256/2)-142=-14 pixels to the right (so 14 pixels to the left)
(256/2)-11=117 pixels down

As I say, depends how you're displaying things but I think that playing
with these numbers should do the job.

John

On Fri, May 02, 2008 at 05:59:20PM +0530, Vishwa wrote:
> Sorry, it still not working.
> Here are my values:
> 
> lon =  -0.127144
> lat  = 51.506324999991364
> zoom = 12
> 
> From which i calculate:
> xtile = 2046
> ytile = 1362
> 
> Also, as you suggested i tried to take the decimal part and determine how
> much the tiles have to be moved:
> X
> 2046.5533838222223
> 0.5533838222223 X 256 = 141.6 = 142 pixels
> 
> Y
> 1362.0441915021011
> 0.044191502101057267 * 256 = 11.31 = 11pixels
> 
> Is this calculation is according to what you have suggested?
> The end result is not centering the map.
> 
> Regards,
> Vishwa
> 
> On Wed, Apr 30, 2008 at 4:12 PM, root <john at mckerrell.net> wrote:
> 
> > If you convert the lat/lon to a floating point tile coordinate you can
> > then use the decimal part to tell you how much you need to shift the
> > tiles. Multiply it by 256 and that'll tell you how far. That help?
> >
> > On Wed, Apr 30, 2008 at 03:55:55PM +0530, Vishwa wrote:
> > > i am doing this using C#.Net to create a image out of tiles, and i have
> > to
> > > center the image to the given image
> > >
> > > i know the zoom level, and the center coordianates, and the size of the
> > 3x3
> > > grid. how to center align the map when the center can be anywhere within
> > the
> > > 256x256 center tile?
> > >
> > > thanks
> > > vishwa
> > >
> > >
> > > > On Wed, Apr 30, 2008 at 1:15 PM, Iv??n S??nchez Ortega <
> > > > ivan at sanchezortega.es> wrote:
> > > >
> > > > > El Mi??rcoles, 30 de Abril de 2008, Vishwa escribi??:
> > > > > > In other words, how to know the pixel (x,y) *within the center
> > tile*
> > > > > for a
> > > > > > given lon,lat value.
> > > > >
> > > > > If you're using javascript, please keep in mind that there are
> > > > > OpenLayers
> > > > > functions for this.
> > > > >
> > > > > --
> > > > > ----------------------------------
> > > > > Iv??n S??nchez Ortega <ivan at sanchezortega.es>
> > > > >
> > > > > "Anything that is too stupid to be spoken is sung."
> > > > >  - Voltaire (1694-1778) [poor guy, never knew about rap]
> > > > >
> > > >
> > > >
> >
> > > _______________________________________________
> > > newbies mailing list
> > > newbies at openstreetmap.org
> > > http://lists.openstreetmap.org/cgi-bin/mailman/listinfo/newbies
> >
> >
> > _______________________________________________
> > newbies mailing list
> > newbies at openstreetmap.org
> > http://lists.openstreetmap.org/cgi-bin/mailman/listinfo/newbies
> >

> _______________________________________________
> newbies mailing list
> newbies at openstreetmap.org
> http://lists.openstreetmap.org/cgi-bin/mailman/listinfo/newbies





More information about the newbies mailing list