mapObj.zoomRectangle from Java Mapscript.

Javier Caicedo jcaicedo at CTI.ESPOL.EDU.EC
Tue Dec 12 07:04:18 EST 2006


Well, I don't see anything obviously wrong with your code. I would suggest
trying another javascript library (or another browser?) and see if the
behaviour improves.  Also try setting the last parameter in zoomRectangle
to null, just to see what happens. Regarding your last question, in image
coordinates the 0,0 point is at top left, so miny is actually closer to
the top. It took me some time to grasp the concept...

      0,0____________________________________
        |
        |
        |
        |    __________________(maxx,miny)
        |   |                  |
        |   |                  |
        |   |__________________|
        |  (minx, maxy)
        |

Regards,
Javier Caicedo Espinoza
CTI - ESPOL
Ecuador

>
>     Hello Javier, thanks for the info.
>
>     We have been struggling for some time now with the zoomRectangle and
> every piece of info is appreciated.
>     Concerning the swap of MinY with MaxY in your code, I gotta say this
> caught me off guard.
>      I couldn't get past a "miny >= maxy" error while trying to  use
> zoomRectangle before and went as far as changing and recompiling
> mapzoom.i where there is a consistency check that looks like:
>
> 	if (poPixRect->maxy >= poPixRect->miny) { -- insert nasty error here -- }
>
>
>     thinking I found a bug. I got past the error after that change,
> however the zoom behavior was what could best be described as "all over
> the place". Like zooming to the wrong hemisphere and the like.
>     So I changed mapzoom.i back to the original code and swapped the
> order of arguments on my code following your example, and it worked
> better than the last behavior, however the zoom isn't still quite
> working in a predictable manner.
>     Sometimes when zooming the map will remain at the same zoom factor,
> and just pan a little to the sides or actually zooming out instead of
> going zooming to the passed coordinates. I am running out of ideas as to
> what could be causing this behavior.
>     Here is what I am doing:
>
>       //Current map geo extent
>       String[] extents = ((String) params.get("extent")).split(" ");
>        rectObj extent = new rectObj(Double.parseDouble(extents[0]),
> Double.parseDouble(extents[1]),
>                                      Double.parseDouble(extents[2]),
> Double.parseDouble(extents[3]), mapscript.MS_FALSE);
>        mapa.setExtent(extent);
>
>         //rectangle Pic coords
>         String[] pxCoordZoom = ((String)
> params.get("coordenadas")).split(" ");
>         Double minx = Double.parseDouble(pxCoordZoom[0]);
>         Double miny = Double.parseDouble(pxCoordZoom[1]);
>         Double maxy = Double.parseDouble(pxCoordZoom[2]);
>         Double maxx = Double.parseDouble(pxCoordZoom[3]);
>
>        /*We are using a cropper javascript class and the order the
> rectangle coordinates where being passed was kind of unpredictable and
> causing errors                while trying to create the rectangle with
> the eventual minX > maxX /*
>         double transport;
>         if(minx > maxx){
>             transport = minx;
>             minx = maxx;
>             maxx = transport;
>         }
>         if(miny > maxy){
>             transport = miny;
>             miny = maxy;
>             maxy = transport;
>         }
>
>         rectObj zoomArea = new rectObj(minx, maxy, maxx, miny,
> mapscript.MS_TRUE);   //with MaxY and MinY swapped
>         mapa.zoomRectangle(zoomArea, mapa.getWidth(), mapa.getHeight(),
> extent, getMaxGeorefExtent(mapa));
>
>     Do you see any glaring mistakes that could cause the zoom to behave
> wrongly?
>     What confuses me is the fact that you mentioned that the rectangle
> should be constructed with bottom-left and top-right defined, but isn't
> the MinX and MaxY pair actually top-left?
>
>     Thanks in advance, any scrap of information helps immensely.
>
>     Rod.
>
> --
>
>
> *Rodrigo Del C. Andrade*
> /Estagiário Nível Superior/
> /SIC - SSE - Soluções Segurança Pública/
>
> *DÍGITRO TECNOLOGIA*
> *E-mail:* rodrigo.andrade at digitro.com.br
> <mailto:rodrigo.andrade at digitro.com.br>
> *Fone:* +55 48 3281- / +55 48 3281-7000
> *Fax:* +55 48 3281-7299
> *Site:* www.digitro.com <http://www.digitro.com>
>
> Javier Caicedo wrote:
>> According to the Mapscript API mapObj.zoomRectangle first parameter must
>> be in  image coordinates, so you should set the last parameter of the
>> rectObj constructor to TRUE. Here goes an example from my current
>> project:
>>
>>   //vMap is an instance of mapObj
>>   rectObj rect = vMap.getExtent(); //map coordinates
>>   String [] box = getCurrentRequest().getParameter("box").split(" ");
>>   //box is something like this: 10 10 200 200
>>   //0,0 is at top left, so box defines top left and bottom right corners
>>   double mx = Double.parseDouble(box[0]);
>>   double my = Double.parseDouble(box[1]);
>>   double mxx = Double.parseDouble(box[2]);
>>   double mxy = Double.parseDouble(box[3]);
>>
>>   //bunch of validation code ommitted
>>
>>   rectObj rbox = new rectObj(mx,mxy,mxx,my,mapscriptConstants.MS_TRUE);
>>   //notice the switch of mxy and my
>>   //rectObj constructor requires you define bottom left and top right
>>   //corners. rbox is in image coordinates
>>   vMap.zoomRectangle(rbox,w,h,rect,null);
>>
>> Hopefully this will help you out a little.
>>
>> Regards,
>> Javier Caicedo Espinoza
>> CTI - ESPOL
>> Guayaquil, Ecuador
>>
>>
>>
>
>
>
>



More information about the mapserver-users mailing list