question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot read property 'extendComponentModel' of undefined at bmap.min.js

See original GitHub issue

Version

4.6.0

Steps to reproduce

根据提示引入dist/echarts.min.js和dist/extension/bmap.min.js,参考https://github.com/apache/incubator-echarts/tree/master/extension/bmaphttps://echarts.apache.org/examples/zh/editor.html?c=heatmap-bmap 编写以下前端代码


<script type="text/javascript" src='../static/js/jquery.min.js'></script>
<script type="text/javascript" src='../static/js/bmap.min.js'></script>
<script type="text/javascript" src='../static/js/echarts.min.js'></script>
<script src="http://api.map.baidu.com/api?v=2.0&ak=***"></script>

<script type="text/javascript">
    var myChart = echarts.init(document.getElementById('maps'))

    myChart.showLoading();
        $.get('../static/json/hangzhou-tracks.json', function (data) {

            var points = [].concat.apply([], data.map(function (track) {
                return track.map(function (seg) {
                    return seg.coord.concat([1]);
                });
            }));
            console.log(points);
            myChart.hideLoading();
            var option = {
                animation: false,
                bmap: {
                    center: [120.13066322374, 30.240018034923],
                    zoom: 14,
                    roam: true
                },
                visualMap: {
                    show: false,
                    top: 'top',
                    min: 0,
                    max: 5,
                    seriesIndex: 0,
                    calculable: true,
                    inRange: {
                        color: ['blue', 'blue', 'green', 'yellow', 'red']
                    }
                },
                series: [{
                    type: 'heatmap',
                    coordinateSystem: 'bmap',
                    data: points,
                    pointSize: 5,
                    blurSize: 6
                }]
            };
            myChart.setOption(option);
           // 添加百度地图插件
            var bmap = myChart.getModel().getComponent('bmap').getBMap();
            bmap.addControl(new BMap.MapTypeControl());
    });
</script>

//tips:百度密钥在本地是可以正常使用的,此处用*号表示

What is expected?

希望能够生成和示例( https://echarts.apache.org/examples/zh/editor.html?c=heatmap-bmap )中相似的热力图效果

What is actually happening?

  1. Uncaught TypeError: Cannot read property ‘extendComponentModel’ of undefined at bmap.min.js:22
  2. Uncaught TypeError: Cannot read property ‘getBMap’ of undefined at Object.success ((index):82) at j (jquery.min.js:2) at Object.fireWith [as resolveWith] (jquery.min.js:2) at x (jquery.min.js:4) at XMLHttpRequest.<anonymous> (jquery.min.js:4)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
z384647062commented, Apr 29, 2021

echarts.min.js 需要放在 bmap.min.js 之前引入,不然会报 echarts undefined


另外,如果项目使用的打包环境,不要使用CDN方式引入 echarts.min.jsbmap.min.js,只需要引入一个 http://api.map.baidu.com/api?v=2.0&ak=*** 在代码中:

import * as echarts from 'echarts/core';
import 'echarts/dist/extension/bmap.min.js';
0reactions
aaronyyancommented, May 26, 2021

@z384647062 我现在版本是5.1.1,按照你说的引入,但是地图就没法出来了

更新一下:我这边在开发环境下正常,生产环境下无法显示地图,可能是由于BMap的模块引入之后未被调用,在webpack打包(我使用的umi)的时候被优化掉了; 以下是我的解决方式(注意引用的顺序):

import * as echarts from 'echarts/core';
// import 'echarts/dist/extension/bmap.min.js';
import _m from 'echarts/extension-src/bmap/BMapView';
import _v from 'echarts/extension-src/bmap/BMapModel';
import { version } from 'echarts/extension-src/bmap/bmap';
console.log(version, _m, _v); // 防止webpack优化

Module not found: Error: Can’t resolve ‘echarts/extension-src/bmap/BMapView’ 有遇到吗

确认下node_modules目录下有是否有/echarts/extension-src/bmap/BMapView

https://tva1.sinaimg.cn/large/008i3skNgy1gqvtifhuu5j30f80fa75d.jpg 目录下是有的,我换成import _m from 'echarts/extension/bmap/BMapView';可以

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot read property 'extendComponentModel' of undefined ...
Version 4.6.0 Steps to reproduce 根据提示引入dist/echarts.min.js和dist/extension/bmap.min.js, ...
Read more >
subject:"\[GitHub\] \[echarts\] aaronyyan commented on issue ...
[GitHub] [echarts] aaronyyan commented on issue #12005: Cannot read property 'extendComponentModel' of undefined at bmap.min.js.
Read more >
JQuery & Echarts: Cannot read property 'getProgressive' of ...
I encountered a strange error when using Jquery and echarts: Cannot read property 'getProgressive' of undefined. My code went like:
Read more >
TypeError: Cannot read property 'b' of undefined
Hi everyone, This is a new error that I cannot find on the Jitsi Community. I downloaded the latest Jitsi Meet and put...
Read more >
echarts@5.4.1 - jsDocs.io
getInstanceByDom: (dom: HTMLElement) => EChartsType | undefined; ... util/component.js'; ... Set visual property of single data item ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found