在节点中使用mapv(百度的地图工具)?

时间:2017-07-18 02:55:34

标签: javascript npm

我想将以下代码更改为节点环境。救救我!

代码来自http://mapv.baidu.com/examples/

内容如下:

    var map = new BMap.Map(slice.selector, {
        enableMapClick: false
    });    // 创建Map实例
    map.centerAndZoom(new BMap.Point(105.403119, 38.028658), 5);  // 初始化地图,设置中心点坐标和地图级别
    map.enableScrollWheelZoom(true); // 开启鼠标滚轮缩放

    map.setMapStyle({
        style: 'light'
    });

    var randomCount = 300;

    var data = [];

    var citys = 
    ["北京","天津","上海","重庆","石家庄","太原","呼和浩特","哈尔滨",
     "长春","沈阳","济南","南京","合肥","杭州","南昌","福州","郑州","武汉",
     "长沙","广州","南宁","西安","银川","兰州","西宁","乌鲁木齐","成都",
     "贵阳","昆明","拉萨","海口"];

    // 构造数据
    while (randomCount--) {
        var cityCenter = mapv.utilCityCenter.getCenterByCityName(citys[parseInt(Math.random() * citys.length)]);
        data.push({
            geometry: {
                type: 'Point',
                coordinates: [cityCenter.lng - 2 + Math.random() * 4, cityCenter.lat - 2 + Math.random() * 4]
            },
            count: 30 * Math.random()
        });
    }
    //数据集
    var dataSet = new mapv.DataSet(data);

    var options = {
        fillStyle: 'rgba(255, 50, 50, 0.6)',
        shadowColor: 'rgba(255, 50, 50, 1)',
        shadowBlur: 30,
        globalCompositeOperation: 'lighter',
        methods: {
            click: function (item) {
                console.log(item);
            }
        },
        size: 5,
        draw: 'simple'
    }

    var mapvLayer = new mapv.baiduMapLayer(map, dataSet, options);

我使用“mapv = require('mapv');”导入模块mapv。但我不能得到模块“BMap”,我怎么能得到它?

1 个答案:

答案 0 :(得分:0)

添加 在index.html中 并在你的js代码中使用var BMap = window.BMap