K_Reverter的网页开发记录

要么不做,要么就当作艺术品来做!

导航

Google Maps API 2.0解析(19-GArrow一直不为人知的一种标注)

        //这个类很奇怪,奇怪在于,居然没有任何地方调用它,也就是说,这段代码的存在毫无意义,可能是Google当时正在开发的功能吧
        //看了一下,这个功能是Google的一个没有开发的功能,用来添加一个具有指向功能的标注,非常有意思,就是在某点上显示一个箭头标注,指向目标点,
        //指向的箭头Google用了一系列的图片如下:
        //http://www.google.com/intl/zh-CN_ALL/mapfiles/dir_0.png
        //http://www.google.com/intl/zh-CN_ALL/mapfiles/dir_3.png
        //http://www.google.com/intl/zh-CN_ALL/mapfiles/dir_6.png
        //    ………
        //    ………
        //    ………
        //http://www.google.com/intl/zh-CN_ALL/mapfiles/dir_360.png
        //那我就自作主张给它取名字叫GArrow吧
        //这个类还是蛮有意思的,为什么不开放出来呢?
        function GArrow(point,start,end)
        
{
            
this.point=point;
            
this.start=start;
            
this.end=end
        }

        GArrow.prototype
=new GOverlay();
        GArrow.prototype.initialize
=function(map)
        
{
            
this.map=map;
        }
;
        GArrow.prototype.remove
=function()
        
{
            
var a=this.img;
            
if(a)
            
{
                deposeNode(a);
                
this.img=null
            }

        }
;
        GArrow.prototype.copy
=function()
        
{
            
return new GArrow(this.point,this.start,this.end)
        }
;
        GArrow.prototype.redraw
=function(a)
        
{
            
if(!a)return;
            
var b=this.map;
            
var c=b.getCurrentMapType();
            
if(!this.img||this.mapType!=c)
            
{
                
this.remove();
                
var d=this.getAngle();
                
this.img=CreateImage(getImageSrcByAngle(d),b.getPane(0),GPoint.ORIGIN,new GSize(24,24),true);
                
this.angle=d;
                
this.mapType=c
            }

            
var d=this.angle;
            
var e=Math.floor(-12-12*Math.cos(d));//图片大小是24*24的
            var f=Math.floor(-12-12*Math.sin(d));
            
var g=b.fromLatLngToDivPixel(this.point);
            SetPosition(
this.B,new GPoint(g.x+e,g.y+f))
            
//定位图片
        }
;
        
//获得两点之间连线与竖直向上之间的角度(顺时针方向)
        GArrow.prototype.getAngle=function()
        
{
            
var a=this.map;
            
var b=a.fromLatLngToPixel(this.start);
            
var c=a.fromLatLngToPixel(this.end);
            
return Math.atan2(c.y-b.y,c.x-b.x)
        }
;
        
//根据上面的方法求出的角度获取图片路径
        function getImageSrcByAngle(a)
        
{
            
var b=Math.round(a*60/Math.PI)*3+90;
            
while(b>=120)b-=120;
            
while(b<0)b+=120;
            
return getStaticImageUrl("dir_"+b)
        }
;

posted on 2006-08-18 17:22  K_Reverter  阅读(2751)  评论(2编辑  收藏  举报