C # sogou map API application summary,
Map Initialization
1. Add the reference map API file: <script src = "http://api.go2map.com/maps/js/api_v2.5.1.js" type = "text/javascript"> </script>
2. Website initialization loading event: window. onload = function () {var map = new sogou. maps. Map (document. getElementById ("map_canvas "),{});}
Create a div with the id of map_canvas and customize the div style. The map is automatically loaded when the website is running;
The Code is as follows:
<Html xmlns = "http://www.w3.org/1999/xhtml"> Show mocheng city map
Key code:
Window. onload = function () {var myOptions = {zoom: 10, center: new sogou. maps. point (12956000,482 4875)}; // city coordinate. The coordinate is Beijing coordinate var map = new sogou. maps. map (document. getElementById ("map_canvas"), myOptions );}View Code
Map attributes
Lists common attributes, such as map movement, map type conversion, and jump to a specified city.
The Code is as follows:
<Html xmlns =" http://www.w3.org/1999/xhtml "> <Head id =" Head1 "runat =" server "> <title> </title> <style type =" text/css "> html {height: auto ;} body {height: auto; margin: 0; padding: 0 ;}# map_canvas {width: 1000px; height: 500px; position: absolute ;}@ media print {# map_canvas {height: 950px ;}</style> <script src =" http://api.go2map.com/maps/js/api_v2.5.1.js "Type =" text/javascript "> </script> <script> var map; // create a global variable window. onload = function () {var myOptions = {zoom: 10, center: new sogou. maps. point (12956000,482 4875)}; // specify the city map = new sogou. maps. map (document. getElementById ("map_canvas"), myOptions); // create a map} // setMapTypeId method example function setMapTypeId (num) {// set the map type, for example: // sogou. maps. mapTypeId. ROADMAP common map // sogou. maps. mapTypeId. SATELLITE map // sogou. maps. mapTypeId. HYBRID map of HYBRID satellite and road network // map. setMapTypeId (sogou. maps. mapTypeId. HYBRID) switch (num) {case 1: map. setMapTypeId (sogou. maps. mapTypeId. ROADMAP); break; // normal map case 2: map. setMapTypeId (sogou. maps. mapTypeId. SATELLITE); break; // SATELLITE map case 3: map. setMapTypeId (sogou. maps. mapTypeId. HYBRID); break; // HYBRID map of satellite and road network} // example map of the panBy method manual movement function panBy (a, B) {map. panBy (a, B)} // The setOptions method example shows the specified region function setOptions () {// map center, level, and type map are set at the same time. setOptions ({center: new sogou. maps. point (13522000,364 1093), zoom: 12, mapTypeId: sogou. maps. mapTypeId. ROADMAP})} // The setCenter method example shows that the specified region a and B are map coordinates, and C is map-level function setCenter (a, B, c) {map. setCenter (new sogou. maps. point (a, B), c)} // The fitBounds method example jumps to the function fitBounds () {// sets the range var bounds = new sogou near the Palace Museum. maps. bounds (12955101,482 4738, 12958355,482 7449); // set the map to display the range in full. // note: the bounds value is not set, but the map is adjusted to the appropriate position. fitBounds (bounds )} </script> Map point attributes
A map is a very important attribute. Adding a chart to a map is a common method attribute,
Sogou API provides two types of tracking, default tracking and dynamic addition of tracking
Add by default:
Var location = new sogou. maps. point (12956000,482 4875); // specify the position var map = new sogou. maps. map (document. getElementById ("map_canvas"), {}); // initialize map var marker = new sogou. maps. marker ({position: location, // stroke coordinate title: "stroke", // stroke name label: {visible: true, align: "BOTTOM "}, // map: map,}); // Add a mapView Code
Add dynamic points
Window. onload = function () {// initialize map = new sogou. maps. map (document. getElementById ("map_canvas"), {}); // Add a click event sogou for the map. maps. event. addListener (map, 'click', function (event) {var marker1 = new sogou. maps. marker ({position: event. point, map: map });});}View Code
Ranging Based on two strokes
// Obtain the unique function getInstance (a) {. hasOwnProperty ("_ instance") | (. _ instance = new a); return. _ instance} // 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) + "meter", map: map });}View Code
A small module is created based on the above attributes. The dynamic ranging code on the map is as follows:
<Html xmlns =" http://www.w3.org/1999/xhtml "> <Head id =" Head1 "runat =" server "> <title> </title> <style type =" text/css "> html {height: auto ;} body {height: auto; margin: 0; padding: 0 ;}# map_canvas {width: 1000px; height: 500px; position: absolute ;}@ media print {# map_canvas {height: 950px ;}</style> <script src =" http://api.go2map.com/maps/js/api_v2.5.1.js "Type =" text/javascript "> </script> <script> var map; var num; var Listener; // obtain the unique function getInstance (a) {. hasOwnProperty ("_ instance") | (. _ instance = new a); return. _ instance} window. onload = function () {// initialize map = new sogou. maps. map (document. getElementById ("map_canvas"), {});} function AddCj () {var mypointh; var myPoint; num = 0; // Add a click event for the map, display the current coordinates after clicking, and add a click Ener ing Listener = sogou. maps. event. addListener (map, 'click', function (event) {if (num = 0) {mypointh = myPoint = event. point; // obtain the coordinates of the click position} else {myPoint = mypointh; mypointh = event. point; // obtain the coordinates of the click position} Lines (mypointh, myPoint); num ++;});} function DelCj () {sogou. maps. event. removeListener (Listener)} // 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) + "meter", map: map}); placeMarker (myLatlng, parseInt (distance);} // dynamically Add a lookup point and create a lookup function placeMarker (location, jl) based on the specified coordinates) {var clickedLocation = location; var marker1 = new sogou. maps. marker ({position: location, title: jl + "meters", label: {visible: true, align: "BOTTOM"}, map: map});} function Mapclear () {num = 0; map. clearAll ();} </script>
C language ^ how to use
A1 = 0x01; // 0000 0001
A2 = 0x00; // 0000 0000
A3 = 0x03; // 0000 0011
A4 = 0x02; // 0000 0010
B1 = a1 ^ a2; // 0000 0001
B2 = a1 ^ a3; // 0000 0010
B3 = a1 ^ a4; // 0000 0011
^ XOR operator. The bitwise value is 0 and the difference is 1. See the example above.
//
Examples of simple and practical problems:
====================================
======= A ======= B =========
There are two circuits on the top. The two switches are a and B respectively. The opening status is \ [1], and the closing status is/[0].
If both circuits are enabled or disabled.
If a turns on [1], B turns off [0], and circuit 1 Powers on
=====================
If a disables [0], B enables [1], and circuit 2 powers on.
====================================
In summary, the circuit fails in the and B states simultaneously [0]. When a and B are different, the power is charged [1].
C language ^ how to use
A1 = 0x01; // 0000 0001
A2 = 0x00; // 0000 0000
A3 = 0x03; // 0000 0011
A4 = 0x02; // 0000 0010
B1 = a1 ^ a2; // 0000 0001
B2 = a1 ^ a3; // 0000 0010
B3 = a1 ^ a4; // 0000 0011
^ XOR operator. The bitwise value is 0 and the difference is 1. See the example above.
//
Examples of simple and practical problems:
====================================
======= A ======= B =========
There are two circuits on the top. The two switches are a and B respectively. The opening status is \ [1], and the closing status is/[0].
If both circuits are enabled or disabled.
If a turns on [1], B turns off [0], and circuit 1 Powers on
=====================
If a disables [0], B enables [1], and circuit 2 powers on.
====================================
In summary, the circuit fails in the and B states simultaneously [0]. When a and B are different, the power is charged [1].