[OpenLayers-Dev] Mouse Wheel
Guillaume Sueur
guillaume.sueur at neogeo-online.net
Fri Jul 18 06:20:54 EDT 2008
actually, you may be right. The code for both controls is different :
from MouseDefaults :
defaultWheelUp: function(evt) {
if (this.map.getZoom() <= this.map.getNumZoomLevels()) {
this.map.setCenter(this.map.getLonLatFromPixel(evt.xy),
this.map.getZoom() + 1);
}
},
it means it takes the position of the cursor as the new center.
In navigation control :
wheelChange: function(evt, deltaZ) {
var newZoom = this.map.getZoom() + deltaZ;
if (!this.map.isValidZoomLevel(newZoom)) {
return;
}
var size = this.map.getSize();
var deltaX = size.w/2 - evt.xy.x;
var deltaY = evt.xy.y - size.h/2;
var newRes = this.map.baseLayer.getResolutionForZoom(newZoom);
var zoomPoint = this.map.getLonLatFromPixel(evt.xy);
var newCenter = new OpenLayers.LonLat(
zoomPoint.lon + deltaX * newRes,
zoomPoint.lat + deltaY * newRes );
this.map.setCenter( newCenter, newZoom );
},
this one computes the new center in order to let the previous point
under the cursor.
it looks like the MouseDefault control just acts as Chris said it
shouldn't !
Guillaume
Kyle Mulka a écrit :
> I was using FF3 on Mac. The example link you gave me worked fine though.
>
> I was able to boil down what I was experiencing into a bare minimum
> chunk of code. Use your mouse wheel to zoom in and out of this map to
> see what I mean:
> http://www.kylemulka.com/temp/openlayers/funkywheel.html
>
> Is that behavior expected given the code? I'm not sure why we decided
> to use the MouseDefaults control instead of Navigation. I'll have to
> ask my partner who wrote it.
>
> -Kyle
>
> On Fri, Jul 18, 2008 at 2:06 AM, Guillaume Sueur
> <guillaume.sueur at neogeo-online.net> wrote:
>> actually Kyle is not pointing at the same problem. The former discussion
>> asked why OL didn't center the map on the position of the mouseWheel, which
>> is indeed a bad idea.
>> As Chris said in his reply, OL zoomwheel keeps the same point under the
>> cursor, just as GoogleMaps does.
>> But it looks like Kyle doesn't get this kind of behaviour, which works
>> perfectly fine in the examples page
>> (http://www.openlayers.org/dev/examples/example-list.html)
>>
>> any more hint Kyle (browser version for instance ? )
>>
>> Thanks
>>
>> Guillaume
>>
>> bartvde at osgis.nl a écrit :
>>> It's by design, see:
>>>
>>> http://www.mail-archive.com/users@openlayers.org/msg03396.html
>>>
>>> Best regards,
>>> Bart
>>>
>>>> When you use the mouse wheel to zoom in and out, shouldn't the point
>>>> under the mouse cursor stay the same? This works as expected with
>>>> Google Maps, but fails miserably with OpenLayers. I'm wondering if
>>>> this is something that would be easy to fix, assuming the default
>>>> behavior is to just zoom from the center of the map instead of from
>>>> the mouse position.
>>>>
>>>> --
>>>> Kyle Mulka
>>>> http://www.kylemulka.com
>>>> _______________________________________________
>>>> Dev mailing list
>>>> Dev at openlayers.org
>>>> http://openlayers.org/mailman/listinfo/dev
>>>>
>>>
>>> _______________________________________________
>>> Dev mailing list
>>> Dev at openlayers.org
>>> http://openlayers.org/mailman/listinfo/dev
>>>
>>
>>
>
>
>
--
More information about the Dev
mailing list