Getting zoomscroll to work with baselayers in fusion 1.1 (MapGuide)

2 messages Options
Embed this post
Permalink
Måns Beckman

Getting zoomscroll to work with baselayers in fusion 1.1 (MapGuide)

Reply Threaded More More options
Print post
Permalink
Some javascript/style in this post has been disabled (why?)

Hi,

 

Fusion 1.1 is great, but zooming with the scrollwheel doesn’t work. http://trac.osgeo.org/fusion/ticket/59 (like in Zac’s case my map is in a locale coordinate system)

I have been trying to figure out why, but I’ve had some trouble and some success.

 

So I started with figuring out that we don’t get the same reply from the server when we use ordinary maps as when we use baselayers maps. Something is happening inside OpenLayers. The same parameters are sent from wheelChange to setExtents, after setExtents something is happening that makes the map stay in the same scale.

 

But what could be seen was that zooming in using the zoom tool or the navigator worked, so my quick and dirty hack was to copy some code from the navigator widget into wheelChange.

 

(I know this code is ugly, but it kind of works.)

 

    wheelChange: function(evt, deltaZ) {

var deltaRes = deltaZ > 0 ? 0.5 : 2;

var activeWidget = null;

        if (this.oActiveWidget) {

          activeWidget = this.oActiveWidget;

          this.deactivateWidget(this.oActiveWidget);

        }

                                                         

        var center = this.getCurrentCenter();

        this.zoom(center.x, center.y, deltaRes);

//Event.stop(e);

        if (activeWidget) {

          this.activateWidget(activeWidget);

        }

},

 

This will work, but zooms into the center of the map instead of where the cursor is. I tried to send a different center to the zoom function, like the newCenter calculated in the original wheelChange function, but it still kept zooming into the center of the map, even if I send fixed coordinates like 0,0. This is just strange.

 

So if anyone can make my code better or find another solution it would be great.

 

Cheers

Måns

 

 

-----------------------------------------------------------

Måns Beckman

Man and Machine

Fabriksgatan 13

412 50 Göteborg

Phone: +46 31 - 762 8182

Mobile: +46 733 - 38 83 19

 


_______________________________________________
fusion-users mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/fusion-users
Paul Spencer-2

Re: Getting zoomscroll to work with baselayers in fusion 1.1 (MapGuide)

Reply Threaded More More options
Print post
Permalink
Thanks for digging into this Måns.  I suspect that the difference is  
something to do with the fixed zoom levels in tiled maps vs non-fixed  
in regular maps.

You might want to change your approach here and try something like this:

wheelChange: function(evt, deltaZ) {
     var size    = this.oMapOL.getSize();
     var deltaX  = size.w/2 - evt.xy.x;
     var deltaY  = evt.xy.y - size.h/2;
     if (this.fractionalZoom) {
         var deltaRes = deltaZ > 0 ? 0.5 : 2;  //TODO: use some sort  
of factor here
         var newRes  = this.oMapOL.baseLayer.getResolution()*deltaRes;
     } else {
         var newZoom = this.olMap.getZoom() + deltaZ;
         if (!this.olMap.isValidZoomLevel(newZoom)) {
             return;
         }
         var newRes  =  
this.olMap.baseLayer.getResolutionForZoom(newZoom);
     }
     var zoomPoint = this.oMapOL.getLonLatFromPixel(evt.xy);
     var newCenter = new OpenLayers.LonLat(
                         zoomPoint.lon + deltaX * newRes,
                         zoomPoint.lat + deltaY * newRes );
     var newBounds = new OpenLayers.Bounds(
                         newCenter.lon - size.w*newRes/2,
                         newCenter.lat - size.h*newRes/2,
                         newCenter.lon + size.w*newRes/2,
                         newCenter.lat + size.h*newRes/2);
     this.setExtents(newBounds);
}

Please let me know what you get working and I will incorporate it into  
Fusion.

Cheers

Paul

On 4-Nov-08, at 3:17 AM, Måns Beckman wrote:

> Hi,
>
> Fusion 1.1 is great, but zooming with the scrollwheel doesn’t work. http://trac.osgeo.org/fusion/ticket/59 
>  (like in Zac’s case my map is in a locale coordinate system)
> I have been trying to figure out why, but I’ve had some trouble and  
> some success.
>
> So I started with figuring out that we don’t get the same reply from  
> the server when we use ordinary maps as when we use baselayers maps.  
> Something is happening inside OpenLayers. The same parameters are  
> sent from wheelChange to setExtents, after setExtents something is  
> happening that makes the map stay in the same scale.
>
> But what could be seen was that zooming in using the zoom tool or  
> the navigator worked, so my quick and dirty hack was to copy some  
> code from the navigator widget into wheelChange.
>
> (I know this code is ugly, but it kind of works.)
>
>     wheelChange: function(evt, deltaZ) {
> var deltaRes = deltaZ > 0 ? 0.5 : 2;
> var activeWidget = null;
>         if (this.oActiveWidget) {
>           activeWidget = this.oActiveWidget;
>           this.deactivateWidget(this.oActiveWidget);
>         }
>
>         var center = this.getCurrentCenter();
>         this.zoom(center.x, center.y, deltaRes);
> //Event.stop(e);
>         if (activeWidget) {
>           this.activateWidget(activeWidget);
>         }
> },
>
> This will work, but zooms into the center of the map instead of  
> where the cursor is. I tried to send a different center to the zoom  
> function, like the newCenter calculated in the original wheelChange  
> function, but it still kept zooming into the center of the map, even  
> if I send fixed coordinates like 0,0. This is just strange.
>
> So if anyone can make my code better or find another solution it  
> would be great.
>
> Cheers
> Måns
>
>
> -----------------------------------------------------------
> Måns Beckman
> Man and Machine
> Fabriksgatan 13
> 412 50 Göteborg
> Phone: +46 31 - 762 8182
> Mobile: +46 733 - 38 83 19
>
> _______________________________________________
> fusion-users mailing list
> [hidden email]
> http://lists.osgeo.org/mailman/listinfo/fusion-users


__________________________________________

    Paul Spencer
    Chief Technology Officer
    DM Solutions Group Inc
    http://research.dmsolutions.ca/

_______________________________________________
fusion-users mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/fusion-users