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:
euzuro
2006-05-22 09:55:20 +00:00
parent af7dc7661a
commit 78588aa8ea
2 changed files with 36 additions and 0 deletions

View File

@@ -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