Sogou Map API Usage Examples Tutorial _javascript tips

Source: Internet
Author: User

This example describes the application of Sogou map API, which is a very practical technique. Share to everyone for your reference. The implementation methods are as follows:

Initialization of a map

1, add the reference map of the API file:

<script src= "Http://xiazai.jb51.net/201409/other/api_v2.5.1.js" type= "Text/javascript" ></script>

2, the site initialization Load event:

Window.onload = function () { 
var map = new Sogou.maps.Map (document.getElementById ("Map_canvas"), {});
 

Create a div with id map_canvas, custom div style, Web site runtime map automatically loaded;

The specific code is as follows

 
 

Specify Show Mo City map

The key code is as follows:

Window.onload = function () { 
var myoptions = {zoom:10,center:new Sogou.maps.Point (12956000, 4824875)};//City coordinates, this coordinate is Beijing coordinate
var map = new Sogou.maps.Map (document.getElementById ("Map_canvas"), myoptions); 


Map Properties Understand

Enumerate some of the commonly used properties such as: Map movement, map type conversion, jump to the designated city

The specific code is as follows

 

Map Stroke Properties

The important attribute on the map, add a stroke to the map, is a common method attribute,

Sogou API provides two kinds of stroke filling form default strokes and dynamic add strokes

Default stroke Add:

var location = new Sogou.maps.Point (12956000, 4824875); Specify the location of the stroke
var map = new Sogou.maps.Map (document.getElementById ("Map_canvas"), {});//Initialize map
var marker = new Sogou.maps.Marker ({
 position:location,//stroke coordinates
 title: stroke,///Stroke name
 Label: {visible:true, align: "BOTTOM"} ,//Stroke display Form
 map:map, 
 });//Add stroke to map

Dynamic Stroke Add

Window.onload = function () { 
//Initialize map
 = new Sogou.maps.Map (document.getElementById ("Map_canvas"), {}); c15/>//Add click event for map
sogou.maps.event.addListener (map, ' click ', Function (event) {
 var marker1 = new Sogou.maps.Marker ({
 position:event.point, 
 map:map
 });
 } 


ranging from two strokes

Gets the unique example
function getinstance (a) {
 a.hasownproperty ("_instance") of the Class | | (a._instance = new A);
 Return a._instance
}
//Two-point connected
function Lines (MYLATLNG, mypoint) { 
 var convertor = getinstance ( Sogou.maps.Convertor);
 var distance = convertor.distance (mylatlng, mypoint);
 Two-point link
 var line = new Sogou.maps.Polyline ({
 path: [Mylatlng, MyPoint],
 strokecolor: "#FF0000",
 strokeopacity:1.0,
 strokeweight:1,
 title:parseint (distance) + "M",
 Map:map
 }); 


According to the above properties to do a small module, the map dynamic ranging code is as follows:

 

Hopefully this article will help you with your Sogou map development

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.