Implement 51Map Map Interface (sample code) _javascript Tips

Source: Internet
Author: User

51MAP provides a map interface for free The following are call interfaces and implement geographic tagging, storage, modification, and echo features.
51 Map URL: http://api.51ditu.com/

Introducing in a Web page

Copy Code code as follows:

<script type= "Text/javascript" src= "Http://api.51ditu.com/js/maps.js" ></script>

To mark on a map:
Copy Code code as follows:

Map marking
$ (document). Ready (function () {
var ico=new lticon ("<c:url value= '/images/manposition.gif '/>", [24,24],[12,12]);
var map=new ltmaps ("Mapdiv");//Map Object
var Controlb; Marking controls
Map.centerandzoom ("Tianjin", 5);//Tianjin
Map.handlemousescroll ()//mouse wheel
var controlzoom = new Ltstandmapcontrol ()//Zoom control
Map.addcontrol (Controlzoom);
Controlb = new Ltmarkcontrol ();//Add callout control and bind event to button
Controlb.setvisible (FALSE);
document.getElementById ("Addposition"). Onclick=function () {Controlb.btnclick ()};
Map.addcontrol (CONTROLB);
Ltevent.addlistener (Controlb, "MouseUp", function () {Getpoi (Controlb)});
})

Copy Code code as follows:

Perform this function when adding annotations
function Getpoi (controlb) {
var poi = Controlb.getmarkcontrolpoint ();
$ ("#x"). Val (Poi.getlongitude ()); X,y the input tag ID through it to the background storage location
$ ("#y"). Val (Poi.getlatitude ());
}

Copy Code code as follows:

<div id= "Mapdiv" style= "width:300px; height:200px; position:static; " >
<div align= "center" style= "MARGIN:12PX;" >
<a href= "http://api.51ditu.com/docs/mapsapi/help.html" target= "_blank"
style= "COLOR: #D01E14; Font-weight:bolder; font-size:12px; " > don't see the map please click here </a>
</div>
</div>

To echo the callout in the read graph:
Copy Code code as follows:

Map echo
$ (document). Ready (function () {
Map ("Mapdiv");
})
Map
function Map (DIV) {
var map=new ltmaps (DIV);//Map Object
var marker=new ltmarker (New Ltpoint ($ ("#x"). Val (), $ ("#y"). Val ());//Create Callout
Map.handlemousescroll ()//mouse wheel Zoom
Map.centerandzoom (The New Ltpoint ($ ("#x"). Val (), $ ("#y"). Val (), 5); Display a map in the center of coordinates
Map.addoverlay (marker)//Add annotation to map
}

Modify the annotation on the map:
Copy Code code as follows:

Map echo
$ (document). Ready (function () {
Map ("Mapdiv");
})
Map
function Map (DIV) {
var map=new ltmaps (DIV);//Map Object
var marker=new ltmarker (New Ltpoint ($ ("#x"). Val (), $ ("#y"). Val ());//Create Callout
Map.handlemousescroll ()//mouse wheel Zoom
Map.centerandzoom (The New Ltpoint ($ ("#x"). Val (), $ ("#y"). Val (), 5); Display a map in the center of coordinates
Map.addoverlay (marker)//Add annotation to map
var controlzoom = new Ltstandmapcontrol ();
Map.addcontrol (Controlzoom);
To add a callout control and bind the event to a button
var controlb = new Ltmarkcontrol ()//Tag control
Controlb.setvisible (FALSE);
document.getElementById ("Addposition"). Onclick=function () {map.removeoverlay (marker,true); ControlB.btnClick ()};
Map.addcontrol (CONTROLB);
Ltevent.addlistener (Controlb, "MouseUp", function () {Getpoi (Controlb)});
}
Perform this function when adding annotations
function Getpoi (controlb) {
var poi = Controlb.getmarkcontrolpoint ();
$ ("#x"). Val (Poi.getlongitude ());
$ ("#y"). Val (Poi.getlatitude ());
}

Other parameter settings:
Can customize callout icon style
Copy Code code as follows:

var ico=new lticon ("<c:url value= '/images/manposition.gif '/>", [24,24],[12,12]);//Create Icon Object
var marker=new ltmarker (New Ltpoint ($ ("#x"). Val (), $ ("#y"). Val (), ICO);//Create Callout
The callout can be displayed when the mouse is moved to the callout
Ltevent.addlistener (marker, "mouseover", function () {this.openinfowinhtml (' callout content ')});

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.