POINT TO PIXEL
Ace Suares
ace at SUARES.NL
Sat Aug 6 20:38:20 PDT 2005
On Wednesday 08 June 2005 4:23, G Casey wrote:
> Does anyone have a good way to convert point in meters to pixel I am
> trying to compute this for the ability to zoom to a point without a
> click.
>
> the click2map (php mapscript) function (below) works however i need
> to solve for click_x and click_y for a large extent with a known x_map
> and y_map. I have tried and seem to be getting very strange numbers.
>
> Why can I not just solve for click_x with a known x_map ????
My 'map2click' function seems to work...
you feed it a mapObject and a rectObj, the latter being the bounds of the
shape you are looking for.
The function calculates the center of the rectangle, and return the pixel
value.
I use it in http://www.la21.nl/resultaten2005 and it seems to do what it
must do. It makes sure the selected shape will be centered in the small
'zoom_map'.
// If there are any doubts: I wrote this and it's licensed under the GPL.
function map2click ( $map, $bounds ) {
$bounds_average_x = ( $bounds->maxx + $bounds->minx ) / 2;
$bounds_average_y = ( $bounds->miny + $bounds->maxy ) / 2;
$x_pct = ( ( $bounds_average_x - $map->extent->minx ) /
( $map->extent->maxx - $map->extent->minx ) );
$y_pct = ( ( $bounds_average_y - $map->extent->miny ) /
( $map->extent->maxy - $map->extent->miny ) );
$x_map = intval( $map->width * $x_pct );
$y_map = intval( $map->height * (1 - $y_pct) );
return array( $x_map, $y_map );
}
// take care about wrapping caused by mailer.
--
"To be nobody but yourself in a world which is doing its best,
night and day, to make you like everybody else, means to fight
the hardest battle any human being can fight
and never stop fighting."
- E. E. Cummings
Ace Suares' Internet Consultancy
mail: PObox 2599, 4800 CN Breda, The Netherlands
phone: +31 6 244 33 608 (Jan Veuger, support Netherlands)
emergency: +599 786 23 73
voicemail & fax: +31 848 707 705
web: http://www.suares.nl email: support at suares.nl
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/mapserver-users/attachments/20050806/3028acbe/attachment.sig>
More information about the MapServer-users
mailing list