Google Map API Tutorial: adding a control button to a Map using a GControl object

Source: Internet
Author: User

Today, Google has recorded 5900 pieces of my website maps, and Baidu has begun to include them ~ The Google map api tutorial I wrote today is about adding a control button on Google Maps and using GControl objects of Google Map APIs, use the initialize method to insert a div to the map, set the button position through new GControlPosition, and add this button through the addControl method of Gmap. The final result is as follows:

Implementation Method Principle Analysis

First, create a GControl prototype control and define its initialize method: Create a div and create the onclick event of the div. Finally, use gmap. getContainer (). appendChild (buttonDiv) is inserted into the map.
Finally, we define the getDefaultPosition method and use the GControlPosition object to set the specific position of the map where the button is located.

Google Map API code function control (){};
Control. prototype = new GControl ();
Control. prototype. initialize = function (gmap ){
Var buttonDiv = document. createElement ("div ");
ButtonDiv. id = "control ";
ButtonDiv. appendChild (document. createTextNode ("Clear punctuation "));
ButtonDiv. onclick = function (){
Gmap. clearOverlays ();
};
Gmap. getContainer (). appendChild (buttonDiv );
Return buttonDiv;
};

Control. prototype. getDefaultPosition = function (){
Return new GControlPosition (G_ANCHOR_TOP_LEFT, new GSize (510, 7 ));
};

Finally, we can use gmap. addControl (new control (); to add this button to the map.

Source: http://www.js8.in/564.html

Related Article

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.