GIS network topology application of Baidu Map and HT for web

Source: Internet
Author: User

In the "HT for Web integration openlayers implementation of GIS Map Application" chapter introduces the integration of HT for Web and Openlayers, many friends respond to the domestic use of more than Baidu map, although the integration of the principle of the integrated Baidu map with openlayers consistent, But different GIS engine client combined with code details or a lot of differences, custom map style is completely different, so I will introduce the next HT and Baidu Map integration scheme, this time we'll improve the previous example, in addition to representing the city's topological nodes, and then increase the connection between the provincial capital and cities, Realize the flow effect of network topology link.

Baidu Map has a variety of client SDK, we use the nature of the JavaScript version of the API, Baidu Map version 2.0 added a lot of new features, such as the ability to customize the map style template, in this case we deliberately set a style: ' Midnight ' dark background style. The location to insert the map is not the same as openlayers, through MapDiv.firstChild.firstChild.appendChild (view), insert, ZIndex These properties are OK no need to set.

The conversion of coordinates from latitude and longitude to planar coordinates is the Map.pointtopixel function, via Node.setposition (Map.pointtopixel (lon, LAT)), and HT can be set. Node corresponds to the plane logical coordinates, through the Map.pixeltopoint (new Bmap.pixel (x, y)) can convert the plane coordinates into latitude coordinates, we listen to the node element is dragged and the end of the endmove need to recalculate the latitude and longitude of the current position.

Map data is the first of the provincial capitals in each province, so we built a larger size with a progressive color to represent the capital city, while other cities build HT at the same time. The edge is connected to the provincial capital node, and the Ht-flow.js plug-in of HT is introduced, only Graphview.enableflow (60) is required, and a word can start the mobile connection function, and each edge connection can have a lot of flow.* The relevant flow reference controls the flow effect, and here's a simple example where we don't need to make a custom, keeping the HT default flow parameters cool enough.

In addition through Graphview.setlayers ([' Edgelayer ', ' Nodelayer ']), we set up two layers for the topology, Node.setlayer (' Nodelayer '), and Edge.setlayer (' Edgelayer ') makes the element nodes all appear on the line, from this detail you can find that previously needed in the GIS SDK extension functions can also be implemented in the Graphview of HT, the map is just as the background, the business logic code is completely in the more flexible and powerful HT model.

Other aspects of the details also by the monitoring map scaling and other operations on the topological elements of the relocation, as well as the monitoring interaction decision Graphview or map control and so on are similar to the previous article, here is no longer introduced, the following is the operation of video, capture and source code for everyone to refer to, Such a combination can be perfect Baidu map rich map data information, and HT powerful logical topology function, otherwise, relying on the Baidu Map SDK API expansion, users can only do some simple effect, such as the line flow and other effects are far less than HT such a row of code to be done easy. Http://v.youku.com/v_show/id_XODQxMDcwNjQ0.html

var Datamodel = new ht.              Datamodel (); var graphview = new Ht.graph.GraphView (Datamodel);   var map = null;   function init () {map = new Bmap.map ("map");                          var point = new Bmap.point (116.404, 39.915);                    Map.addtilelayer (New Bmap.trafficlayer ());                    Map.centerandzoom (point, 4);                       Map.enablescrollwheelzoom ();                               Map.addcontrol (New Bmap.navigationcontrol ()); Map.setmapstyle ({features: ["Road", "building", "water", "Land"],style: ' Midnight '}); var view = Graphview.getview (); View.classname = ' Graphview '; var mapdiv = document.getElementById (' map '); MapDiv.firstChild.firstChild.appendChild (view); Map.addeventlistener (' MoveStart ', function (e) {view.style.opacity = 0;});    Map.addeventlistener (' MoveEnd ', function (e) {view.style.opacity = 1; Resetposition ();                }); Map.addeventlistener (' DragStart ', function (e) {view.style.opacity = 0; }); map.addeventlisteNER (' Dragend ', function (e) {view.style.opacity = 1; Resetposition ();                                });                Map.addeventlistener (' Zoomstart ', function (e) {view.style.opacity = 0;});    Map.addeventlistener (' Zoomend ', function (e) {view.style.opacity = 1; Resetposition ();                }); Graphview.setlayers ([' Edgelayer ', ' Nodelayer ']); graphview.enableflow; Graphview.enabletooltip (); Graphview.gettooltip = function (event) {var data = This.getdataat (event); if (Data instanceof ht. Node) {return ' city: ' + data.s (' note ') + ' Longitude: ' + data.lonLat.lng + ' dimension: ' + Data.lonLat.lat;} return null;}; graphview.isvisible = function (data) {return map.getzoom () > 1 | | this.isselected (data);}; graphview.isnotevisible = function (data) {return map.getzoom () > 8 | | this.isselected (data);}; Graphview.getlabel = function (data) {if (Data instanceof ht.                    Node) {return ' Longitude: ' + data.lonLat.lng + ' \ n dimension: ' + Data.lonLat.lat;} };graphview.islabelvisible = function (data) {return map.getzoom () &GT 9 | | this.isselected (data);}; GRAPHVIEW.MI (function (e) {if (E.kind = = = ' Endmove ') {Graphview.sm (). each (function data) {if (Data instanceof ht.                                Node) {var position = Data.getposition (), x = position.x + graphview.tx (), y = position.y + graphview.ty (); Data.lonlat = Map.pixeltopoint (new Bmap.pixel (x, y)); }                            });}}); Graphview.setautoscrollzone ( -1); graphview.handlescroll = function () {};graphview.handlepinch = function () {};var Handleclick = function (e) {var data = Graphview.getdataat (e); if (data) {e.stoppropagation ();} else if (E.metakey | | e.ctrlkey) {e.stoppropagation ();}};                Graphview.getview (). AddEventListener (' Click ', Handleclick, false); Graphview.getview (). AddEventListener (' DblClick ', Handleclick, false); Graphview.getview (). AddEventListener (HT. Default.istouchable? ' Touchstart ': ' MouseDown ', Handleclick, False) Window.addeventlistener ("Resize", function (e) {graphview.invalidate (                 );}, False); var color =Randomcolor (), province = Null;lines = China.split (' \ n '); for (var i=0; i<lines.length; i++) {line = Lines[i].trim (); if ( Line.indexof (' "') = = = 0) {color = Randomcolor ();p rovince = null;} Else{var ss = Line.split ("); if (ss.length = = = 3) {var node = CreateNode (Parsefloat (SS[1].SUBSTR (3)), parsefloat (ss[2). SUBSTR (3)), SS[0].SUBSTR (3), color); if (province) {var edge = new ht. Edge (Province, node); EDGE.S ({' Edge.center ': true, ' edge.width ': 1, ' Flow ': true}); edge.s Etlayer (' Edgelayer ');d atamodel.add (edge);}                                    Else{province = Node;node.s ({' shape.gradient ': ' Radial.center ',                                    ' Border.type ': ' Circle ', ' border.width ': 1, ' border.color ': ' Rgba (200, 200, 200, 0.5) '                }); Node.setsize (15, 15);}}} }function CreateNode (Lon, LAT, name, color) {var node = new ht.                   Node (); Node.s ({' Shape ': ' Circle ', ' shape.background ': color, ' note ': Name, ' Label.background ': ' Rgba (255, 255, 0, 0.5) ', ' select.type ': ' Circle '}); Node.setlayer (' Nodelayer '); nod E.setsize (Ten), var lonlat = new Bmap.point (lon, LAT);            Node.setposition (Map.pointtopixel (Lonlat)); Node.lonlat = LONLAT;GRAPHVIEW.DM (). Add (node); return node;} function Resetposition (e) {graphview.tx (0), graphview.ty (0);d Atamodel.each (function (data) {if (Data instanceof ht.   Node) {var Lonlat = Data.lonlat,position = Map.pointtopixel (Lonlat);                           Data.setposition (POSITION.X,POSITION.Y);            }}); }


GIS network topology application of Baidu Map and HT for web

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.