Baidu Map Custom Overlays

Source: Internet
Author: User

<script>varMap =NewBmap.map (' Allmap '); varBcenter =NewBmap.point (116.404,39.915); Map.centerandzoom (Bcenter,11); //Custom Overlays    functionMyoverlay (point,text,mouseovertext) { This. _point =Point ;  This. _text =text;  This. _overtext =Mouseovertext; }        //Inherit the overlay APIMyoverlay.prototype =NewBmap.overlay (); //initializing a custom overlayMyOverlay.prototype.initialize =function(map) { This. _map =map; //Create div Tags        vardiv = This. _div = document.createelement (' div '); Div.style.position= ' absolute '; Div.style.zIndex= BMap.Overlay.getZIndex ( This. _point.lat); Div.style.backgroundColor= ' #EE5D5B '; Div.style.border= ' 1px solid #BC3B3A '; Div.style.color= ' White '; Div.style.height= ' 18px '; Div.style.padding= ' 2px '; Div.style.lineHeight= ' 18px '; Div.style.whiteSpace= ' nowrap '; Div.style.MozUserSelect= ' None '; Div.style.fontSize= ' 12px '; //Create a span label        varspan = This. _span = document.createelement (' span ');        Div.appendchild (span); Span.appendchild (document.createTextNode ( This. _text)); varthat = This; //the piercing of the arrows        varArrow = This. _arrow = document.createelement (' div '); Arrow.style.background= "url (http://map.baidu.com/fwmap/upload/r/map/fwmap/static/house/images/label.png) no-repeat"; Arrow.style.position= "Absolute"; Arrow.style.width= "11px"; Arrow.style.height= "10px"; Arrow.style.top= "22px"; Arrow.style.left= "10px"; Arrow.style.overflow= "hidden";        Div.appendchild (arrow); //Tag Binding Event    /*div.onmouseover = function () {This.style.backgroundColor = "#6BADCA";            This.style.borderColor = "#0000ff";            This.getelementsbytagname ("span") [0].innerhtml = That._overtext;        Arrow.style.backgroundPosition = "0px-20px";            } div.onmouseout = function () {This.style.backgroundColor = "#EE5D5B";            This.style.borderColor = "#BC3B3A";            This.getelementsbytagname ("span") [0].innerhtml = That._text;        arrow.style.backgroundPosition = "0px 0px"; }        */        //in a container that is added to the overlaymap.getpanes (). Labelpane.appendchild (Div); returnDiv; }        //Drawing CoveringsMyOverlay.prototype.draw =function(){        varMap = This. _map; varPixel = Map.pointtooverlaypixel ( This. _point);  This. _div.style.left = Pixel.x-parseint ( This. _arrow.left) + ' px ';  This. _div.style.top = pixel.y-30 + ' px '; }        //Overlay DisplayMyOverlay.prototype.show =function(){        if( This. _div) {             This. _div.style.display = "; }    }        //Hide CoverMyOverlay.prototype.hide =function(){        if( This. _div) {             This. _div.style.display = ' None '; }    }        //Custom Overlay Add EventMyOverlay.prototype.addEventListener =function(event, fun) { This. _div[' on ' + event] =Fun ; }        varMyoverlay =NewMyoverlay (Bcenter, ' mouse up to see ', ' Mouse down to see ');    Map.addoverlay (Myoverlay); Myoverlay.addeventlistener (' Click ',function() {alert (' Register Click event '); })    </script>
View Code

Baidu Map Custom Overlays

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.