REsize window question

Stéphane RIFF stephane.riff at CERENE.FR
Tue Apr 5 10:52:19 EDT 2005


To close this post i give what i did, it's not
as good as i hope but if someone interested.

$w_ratio = $old_width / $new_width;
$h_ratio = $old_height / $new_height;

$new_geo_width = ($xmax - $xmin) / $w_ratio;
$new_geo_height = ($ymax - $ymin) / $h_ratio;

$w_geo_diff = ($xmax - $xmin) - $new_geo_width ;
$h_geo_diff  = ($ymax - $ymin) - $new_geo_height ;

$map->setextent( $xmin+$w_geo_diff/2 , $ymin+$h_geo_diff/2 ,
$xmax-$w_geo_diff/2 , $ymax-$h_geo_diff/2 );

$my_point = ms_newpointObj();
$my_point->setXY($width/2,$height/2);
$my_extent = ms_newrectObj();
$my_extent->setextent($map->extent->minx,$map->extent->miny,$map->extent->maxx,$map->extent->maxy);
$gps_map->zoomscale($map->scale,$my_point,$new_width,$new_height,$my_extent);

Voila, the scale varying a little but it's significant
Bye

Stéphane RIFF wrote:

> Thanks for answered....
>
> I realize that my question was not really clear :)
>
> In fact, i want to keep the scale not the extent because
> when the map is resized and (if i keep the extent) of course scale
> change, then
> the active layer may change regards to scale and it's not very intuitive
> for the
> user to understand why.
> So how can i calculate the new extent to keep same scale with different
> map size ?
> I use phpmapscript 4.2.5.
>
> Voila, thanks all
>
> Martin Weinelt wrote:
>
>> On Friday 18 March 2005 09:35, Stéphane RIFF wrote:
>>
>>
>>> My mapserver application need to redraw the map when the window is
>>> resized.
>>> My problem is that i don't know how to keep the same extent
>>> in two map with different size !!!
>>>
>>>
>>
>> Using mapserver CGI you just send MAPEXTENT and MAPSIZE
>> to the CGI (together with layers, etc.) and that's it.
>>
>>
>>
>>> in fact i don't want the map
>>> to change its scale when i resize the window.
>>>
>>>
>>
>> Keeping mapextent at different mapsize yields another scale, no?
>>
>>
>>
>>> How can i calculate the newExtent to do that ???
>>> Is it possible ???
>>>
>>>
>>
>> You  do not calculate it, you just reuse the image extent from the
>> previous
>> map (which can be sent by the CGI together with the image).
>>
>>
>>
>>> How do you handle that kind of function ? example ?
>>>
>>>
>>
>> I do it on the client side with js:
>>
>> function setMapSize() {
>>  // mimg is a div in the doc with the map as background image
>>  mimg.style.backgroundImage='url(images/waiting.gif)';
>>  // a 'wait indicator' is shown until the new image arrives
>>  // w is the browser window
>>  var mh = (w.innerHeight) ? w.innerHeight : d.body.clientHeight;
>>  var mw = (w.innerWidth) ? w.innerWidth : d.body.clientWidth;
>>  mh-=60; mw-=230;             // correct for other elements which
>> also need a bit of screen real estate
>>  mimg.style.width=mw; mimg.style.height=mh;  // set the div to the
>> new size
>>  myMap.mode='browse';            //  myMap is an object which holds
>> some map parameters
>>  myMap.mapsize=[mw,mh];       // ... mapsize for instance
>>  myMap.mapext.set(myMap.imgext.get());        // or map extent - here
>> copied from the last image recieved
>>  var s=myMap.getReqStr('mapsize','mapext');  // this  glues a
>> GET-string for the new map request
>>  getMap(s);                                 // invokes the new map
>> }
>>
>> this is just an example, the same purpose can be served in a more
>> traditional way.
>>
>> Cheers, Martin
>>
>>
>>
>>
>>
>
>



More information about the mapserver-users mailing list