[Chameleon] GeoToPixel Function

Paul Spencer pspencer at dmsolutions.ca
Tue Apr 19 09:55:50 EDT 2005


Paul,

have you looked at how the QuickZoom widget works?  There are a couple 
of problems with having a list of lat/lon values and converting to pixel 
locations:

* you need to make sure that the map actually contains the lat/lon 
values - i.e. the user hasn't zoomed too far already

* this normally means you would set the map extents to the full extents 
possible for the application, then calculate the pixel location (since 
it is guaranteed to be in the extents now) and then zoom to some scale

* this introduces an accuracy problem because the geographic extent of a 
pixel at full map scale is usually quite large and when you zoom in to 
some useful scale, the selected point is often not at the center of the 
view (and possibly not even in the view)

For zooming to points, I've changed to using only geographic extents and 
avoiding pixel conversions for this reason.  It is quite easy to perform 
a scale calculation in PHP to center on some point at a given scale once 
you know how mapsever calculates scale values.

$inchesPerUnit = array(1, 12, 63360.0, 39.3701, 39370.1, 4374754);

$newGeoWidth = (($this->mnScale*$oMap->width) /
                ($oMap->resolution*$inchesPerUnit[$oMap->units])) / 2;

$newGeoHeight = (($this->mnScale*$oMap->height) /
                 ($oMap->resolution*$inchesPerUnit[$oMap->units])) / 2;

$oMap->setextent($poPoint1->x - $newGeoWidth,
                  $poPoint1->y - $newGeoHeight,
                  $poPoint1->x + $newGeoWidth,
                  $poPoint1->y + $newGeoHeight);

Cheers

Paul

Paul Dymecki wrote:
> Hi Ken,
>     Actually i'm creating a new widget.    I have a select list of lat/long
> values i'm trying to zoom into after a user selection. So i would have to
> convert the lat/lon values into something the zoomtopoint function can use.
> ie pixel values.  So far no luck... as all the chameleon widgets i've seen
> get their values from the a point click...
> Paul
> ----- Original Message ----- 
> From: "Ken Sanderson" <ken at rockies.ca>
> To: "Paul Dymecki" <pdymecki at sympatico.ca>
> Cc: <Chameleon at lists.maptools.org>
> Sent: Thursday, April 14, 2005 10:39 AM
> Subject: Re: [Chameleon] GeoToPixel Function
> 
> 
> 
>>By mapObject's zoomtopoint do you mean mapscript's zoompoint function?
>>If so it takes its coordinates in pixels I believe.
>>
>>Are you creating a widget or where are you trying to access the coords?
>>Have you tried grabbing the X and Y values from the form hidden
>>variables MAP_CURSOR_POS_X and MAP_CURSOR_POS_Y, these values would be
>>in pixels?
>>
>>Ken
>>
>>
>>Paul Dymecki wrote:
>>
>>>Hi Paul,
>>>    The Geo2Pix function seems pretty widely used throughout Chameleon,
>>>though i'm having a bit of a time getting it to give me the a pixel
> 
> position
> 
>>>i can pass to a mapObject's zoomToPoint function.  Would i have to
>>>re-project a geo value before passing it to Geo2Pix?
>>>thx,
>>>Paul
>>>
>>>
>>>----- Original Message ----- 
>>>From: "Paul Spencer" <pspencer at dmsolutions.ca>
>>>To: "Paul Dymecki" <pdymecki at sympatico.ca>
>>>Cc: <Chameleon at lists.maptools.org>
>>>Sent: Thursday, April 07, 2005 8:03 PM
>>>Subject: Re: [Chameleon] GeoToPixel Function
>>>
>>>
>>>
>>>
>>>>Paul,
>>>>
>>>>if you are looking for something that is php-accessible, I don't think
>>>>it exists so you'll need a php function for that.  Check the functions
>>>>in geomath.php in chameleon, there is both Geo2Pix and Pix2Geo
>>>>
>>>>Cheers
>>>>
>>>>Paul
>>>>
>>>>Paul Dymecki wrote:
>>>>
>>>>
>>>>>I was wondering if anyone knows of a mapscript function that converts a
>>>>>geoCoded point to a pixel point?
>>>>>thx,
>>>>>Paul
>>>>>
>>>>>_______________________________________________
>>>>>Chameleon mailing list
>>>>>Chameleon at lists.maptools.org
>>>>>http://lists.maptools.org/mailman/listinfo/chameleon
>>>>>
>>>>
>>>>_______________________________________________
>>>>Chameleon mailing list
>>>>Chameleon at lists.maptools.org
>>>>http://lists.maptools.org/mailman/listinfo/chameleon
>>>
>>>
>>>_______________________________________________
>>>Chameleon mailing list
>>>Chameleon at lists.maptools.org
>>>http://lists.maptools.org/mailman/listinfo/chameleon
>>>
> 
> 
> _______________________________________________
> Chameleon mailing list
> Chameleon at lists.maptools.org
> http://lists.maptools.org/mailman/listinfo/chameleon
> 

-- 
+-----------------------------------------------------------------+
|Paul Spencer                           pspencer at dmsolutions.ca   |
+-----------------------------------------------------------------+
|Applications & Software Development                              |
|DM Solutions Group Inc                 http://www.dmsolutions.ca/|
+-----------------------------------------------------------------+


More information about the Chameleon mailing list