Echart series: After using Baidu map extension in Echart3, how to get to Baidu map object

Source: Internet
Author: User

Recently do the project want to overlay on the Baidu map display Echart scatter chart, and then according to the map zoom level and area range to display different scatter plot, this middle toss for a long time. Functional requirements include: (1) Basemap using Baidu Map, (2) can be superimposed on the map display Echart scatter chart, (3) the mouse moved to the above scatter chart, you can float to display relevant information, (4) to obtain the current display area map latitude and longitude range, (5) to respond to the map drag and zoom events;
Here are two options: 1. Baidu map extension using Echart2, 1, 3, 4, 5 can be satisfied, is 2 satisfied, his one series of all the icon style is the same, the same size; 2. Using echart3 Baidu Map extension, can meet the 4 and 5, not meet, because access to Baidu map object;
In the preliminary view of the source code of ECHART2 and Echart3, feel or use echart3 comparison may be quickly realized, after all, echart3 bmap extension Code is limited, we just want to find a way from this extension to Baidu map object, all the follow-up is good. Read and repeat the ECHART3 source code (refer to the Https://github.com/ecomfe/echarts version 3.1.6) in the Extension\bmap folder under the Bmap.js, Bmapcoordsys.js, Bmapmodel.js, Bmapmodel.js, foundwithin the Bmapcoordsys.jsThe Bmap object can be obtained through Bmapmodel in Bmapcoordsys.create, and Bmapmodel is passed through Ecmodel eachcomponent method, by looking at the call stack and discoveringEcmodel is actually the _model object of Echart.
sofind the following method to get the Bmap object
 
   
  
  1. var ecModel = myChart._model;
  2. var bmap = null;
  3. ecModel.eachComponent(‘bmap‘, function (bmapModel) {
  4. if(bmap == null){
  5. bmap = bmapModel.__bmap;
  6. }
  7. });

Once the Bmap object is found, you can use the various APIs of BMAP to respond to his various events (http://developer.baidu.com/map/reference/index.php), such as:
  
 
  1. var pt = bmap.pixelToPoint({
  2. x: 800,
  3. y: 500
  4. });
  5. var pix = bmap.pointToPixel({
  6. lng: 114.31,
  7. lat: 30.52
  8. });
  9. alert(‘lng:‘ + pt.lng + ‘, lag: ‘ + pt.lat);
  10. alert(‘武汉的坐标: x:‘ + pix.x + ‘, y: ‘ + pix.y);
  11. bmap.addEventListener("dragend",function(){
  12. alert(‘缩放等级:‘ + bmap.getZoom());
  13. });
  14. bmap.addEventListener("moveend",function(){
  15. alert(‘缩放等级:‘ + bmap.getZoom());
  16. });





From for notes (Wiz)

Echart series: After using Baidu map extension in Echart3, how to get to Baidu map object

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.