Referencing Kamap a Tile

View: New views
5 Messages — Rating Filter:   Alert me  

Referencing Kamap a Tile

by Ben Brehmer :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I have a Kamap Layer and I need to be able to reference the tile
associated with a viewport pixel. I don't know if this is possible, but
I want to retrieve the tile that lies underneath a certain pixel
position within the viewport.

Any ideas?

Thanks,

Ben

_______________________________________________
Users mailing list
Users@...
http://openlayers.org/mailman/listinfo/users

Re: Referencing Kamap a Tile

by Christopher Schmidt-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Thu, Jan 25, 2007 at 04:36:05PM -0800, Ben Brehmer wrote:
> I have a Kamap Layer and I need to be able to reference the tile
> associated with a viewport pixel. I don't know if this is possible, but
> I want to retrieve the tile that lies underneath a certain pixel
> position within the viewport.

Right click? :)

More seriously, you can get the geographic location from
getLonLatFromPixel or something similar on the Map object, and then look
at the KaMap getURL function:
    getURL: function (bounds) {
        var mapRes = this.map.getResolution();
        var scale = Math.round((this.map.getScale() * 10000)) / 10000;        
        var cellSize = new OpenLayers.Size(mapRes*this.tileSize.w,
                                           mapRes*this.tileSize.h);
        var pX = Math.round(((bounds.left) / cellSize.w) *
                            this.tileSize.w);
        var pY = -Math.round(((bounds.top) / cellSize.h) *
                              this.tileSize.h);
        return this.getFullRequestString(
                      { t: pY,
                        l: pX,
                        s: scale
                      });
    },

Something like this ought  used with px.lon, px.lat instead of
bounds.left, bounds.top might get you there, modulo some rounding
issues. Give it a shot?

Regards,
--
Christopher Schmidt
MetaCarta
_______________________________________________
Users mailing list
Users@...
http://openlayers.org/mailman/listinfo/users

Re: Referencing Kamap a Tile

by Ben Brehmer :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Christopher Schmidt wrote:

> On Thu, Jan 25, 2007 at 04:36:05PM -0800, Ben Brehmer wrote:
>  
>> I have a Kamap Layer and I need to be able to reference the tile
>> associated with a viewport pixel. I don't know if this is possible, but
>> I want to retrieve the tile that lies underneath a certain pixel
>> position within the viewport.
>>    
>
> Right click? :)
>
> More seriously, you can get the geographic location from
> getLonLatFromPixel or something similar on the Map object, and then look
> at the KaMap getURL function:
>     getURL: function (bounds) {
>         var mapRes = this.map.getResolution();
>         var scale = Math.round((this.map.getScale() * 10000)) / 10000;        
>         var cellSize = new OpenLayers.Size(mapRes*this.tileSize.w,
>                                            mapRes*this.tileSize.h);
>         var pX = Math.round(((bounds.left) / cellSize.w) *
>                             this.tileSize.w);
>         var pY = -Math.round(((bounds.top) / cellSize.h) *
>                               this.tileSize.h);
>         return this.getFullRequestString(
>                       { t: pY,
>                         l: pX,
>                         s: scale
>                       });
>     },
>
> Something like this ought  used with px.lon, px.lat instead of
> bounds.left, bounds.top might get you there, modulo some rounding
> issues. Give it a shot?
>
> Regards,
>  
mmmm, yes that would work....and right clicking the tile is not quite
what I need :)

But what I want to do, is reference the top and left attributes of a
tile that is already loaded, with the reference being made from a click
event in the viewport (from which I can retrieve the pixel or lon/lat).

Thanks,

Ben



_______________________________________________
Users mailing list
Users@...
http://openlayers.org/mailman/listinfo/users

Re: Referencing Kamap a Tile

by Tim Schaub-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> But what I want to do, is reference the top and left
> attributes of a tile that is already loaded, with the
> reference being made from a click event in the viewport (from
> which I can retrieve the pixel or lon/lat).

// kaMath
var resolution = kaLayer.getResolution();
var tileMapWidth = resolution * kaLayer.tileSize.w;
var tileMapHeight = resolution * kaLayer.tileSize.h;
var mapPoint = kaLayer.getLonLatFromViewPortPx(viewPortPx);
var tileLeft = tileMapWidth * Math.floor(mapPoint.lon / tileMapWidth);
var tileBottom = tileMapHeight * Math.floor(mapPoint.lat / tileMapHeight);
var kaLeft = tileLeft / resolution;
var kaTop = -(tileBottom + tileMapHeight) / resolution;

kaRegards,
Tim

>
> Thanks,
>
> Ben
>
>
>
> _______________________________________________
> Users mailing list
> Users@...
> http://openlayers.org/mailman/listinfo/users
>

_______________________________________________
Users mailing list
Users@...
http://openlayers.org/mailman/listinfo/users

Re: Referencing Kamap a Tile

by Ben Brehmer :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Ka Thank you.

Ben

Tim Schaub wrote:

>> But what I want to do, is reference the top and left
>> attributes of a tile that is already loaded, with the
>> reference being made from a click event in the viewport (from
>> which I can retrieve the pixel or lon/lat).
>>    
>
> // kaMath
> var resolution = kaLayer.getResolution();
> var tileMapWidth = resolution * kaLayer.tileSize.w;
> var tileMapHeight = resolution * kaLayer.tileSize.h;
> var mapPoint = kaLayer.getLonLatFromViewPortPx(viewPortPx);
> var tileLeft = tileMapWidth * Math.floor(mapPoint.lon / tileMapWidth);
> var tileBottom = tileMapHeight * Math.floor(mapPoint.lat / tileMapHeight);
> var kaLeft = tileLeft / resolution;
> var kaTop = -(tileBottom + tileMapHeight) / resolution;
>
> kaRegards,
> Tim
>
>  
>> Thanks,
>>
>> Ben
>>
>>
>>
>> _______________________________________________
>> Users mailing list
>> Users@...
>> http://openlayers.org/mailman/listinfo/users
>>
>>    
>
> _______________________________________________
> Users mailing list
> Users@...
> http://openlayers.org/mailman/listinfo/users
>  

_______________________________________________
Users mailing list
Users@...
http://openlayers.org/mailman/listinfo/users
LightInTheBox - Buy quality products at wholesale price