adding getPixelFromLonLat() function to Map.js -- the code is lifted from OpenLayers.Layer.Marker's drawMarker() function. also test added to ensure both translation functions return valid objects and that going back and forth is consistent. Note that i only test pixel-lonlat-pixel, because going from lonlat-pixel-lonlat there is loss due to the rounding in the lonlat-pixel phase
git-svn-id: http://svn.openlayers.org/trunk/openlayers@246 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -271,6 +271,23 @@ OpenLayers.Map.prototype = {
|
||||
center.lat - delta_y * res);
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {OpenLayers.LonLat} lonlat
|
||||
*
|
||||
* @returns An OpenLayers.Pixel which is the passed-in OpenLayers.LonLat,
|
||||
* translated into screen pixels given the current extent
|
||||
* and resolution
|
||||
* @type OpenLayers.Pixel
|
||||
*/
|
||||
getPixelFromLonLat: function (lonlat) {
|
||||
var resolution = this.getResolution();
|
||||
var extent = this.getExtent();
|
||||
return new OpenLayers.Pixel(
|
||||
Math.round(1/resolution * (lonlat.lon - extent.left)),
|
||||
Math.round(1/resolution * (extent.top - lonlat.lat))
|
||||
);
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {OpenLayers.LonLat} lonlat
|
||||
* @param {int} zoom
|
||||
|
||||
Reference in New Issue
Block a user