Thanks for input - it's done.



   this.setBounds=function(b){
                this.normalize();
                //the setbounds should be a mathematical formula and not 
guessing around.
                //if you know this formula pease add it here.
                //this.getSize();
                var p1=b.getSW();
                var p2=b.getNE();

                var minlat=p1.getLat();
                var maxlat=p2.getLat();
                var minlng=p1.getLng();
                var maxlng=p2.getLng();

                var minlat360=lat2y(minlat);
                var maxlat360=lat2y(maxlat);
                var centerLng=(minlng+maxlng)/2;
                var centerLat360=(minlat360 + maxlat360)/2;
                var centerLat=y2lat(centerLat360);
                var center=new kPoint(centerLat,centerLng);
                var extendX=Math.abs(maxlat360 - minlat360);
                var extendY=Math.abs(maxlng - minlng);
                if(extendX / this.width < extendY / this.height){
                        var extend=extendX;
                        var screensize=this.width;
                }else{
                        var extend=extendY;
                        var screensize=this.height;
                }
                //alert(extend);
                //zoomlevel 1: 512 pixel
                //zoomlevel 2: 1024 pixel
                //...
                //extend = 360 > zoomlevel 1 , at 512px screen
                //extend = 360 > zoomlevel 2 , at 1024px screen

                //extend at zoomlevel1: extend/360 * 512px
                var scalarZoom=360/extend;
                var screenfaktor= 512/screensize;
                var zoom=(Math.log(scalarZoom / 
screenfaktor))/(Math.log(2)) ;

                if(zoom > 18){
                        zoom=18;
                }
                if(zoom < 1){
                        zoom=1;
                }
                this.setCenter2(center,zoom);

        }





Iván Sánchez Ortega schrieb:
> El 22/03/2010 4:20, Bernhard zwischenbrugger escribió:
>> Given:
>> wgs84: minlat, minlon, maxlat, maxlon
>> screen: width, height
>>
>> Needed:
>> lat,lng, center
>
> http://trac.openlayers.org/browser/trunk/openlayers/lib/OpenLayers/Control/ZoomBox.js
>  
>
>
>
> Cheers,


_______________________________________________
talk mailing list
talk@openstreetmap.org
http://lists.openstreetmap.org/listinfo/talk

Reply via email to