echarts+百度地图

<html>
<head>
<meta name=‘viewport‘ content=‘initial-scale=1.0,user-scalable=no‘ />
<meta http-equiv=‘Content-Type‘ content=‘text/html;charset=utf-8‘ />
<title>地图Test</title>
<style type="text/css">
html{
    height:100%;
}
body{
    height:100%;margin:0;padding:0;
}
.BMap_cpyCtrl {

display: none;

}

.anchorBL {

display: none;

}
#main{height:600px;width:1080px;}
</style>
<script src="./jquery.js"></script>
<script src="./echarts.min.js"></script>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=你申请的百度key"></script>
<script src="./bmap.min.js"></script>
</head>
<body>
<div id=‘bMap‘></div>
<script type=‘text/javascript‘>

            //初始化数据
            //配置样式
            var    styleJson=[
            {
                ‘featureType‘: ‘water‘,
                ‘elementType‘: ‘all‘,
                ‘stylers‘: {
                    ‘color‘: ‘#081843‘
                }
            },
            {
                ‘featureType‘: ‘land‘,
                ‘elementType‘: ‘geometry‘,
                ‘stylers‘: {
                    ‘color‘: ‘#082657‘
                }
            },
            {
                ‘featureType‘: ‘highway‘,
                ‘elementType‘: ‘all‘,
                ‘stylers‘: {
                    ‘visibility‘: ‘off‘
                }
            },
            {
                ‘featureType‘: ‘arterial‘,
                ‘elementType‘: ‘geometry.fill‘,
                ‘stylers‘: {
                    ‘color‘: ‘#103963‘
                }
            },
            {
                ‘featureType‘: ‘arterial‘,
                ‘elementType‘: ‘geometry.stroke‘,
                ‘stylers‘: {
                    ‘color‘: ‘#103963‘,
                    ‘lightness‘: -70
                }
            },
            {
                ‘featureType‘: ‘local‘,
                ‘elementType‘: ‘geometry‘,
                ‘stylers‘: {
                    "visibility": "off"
                }
            },
            {
                "featureType": "railway",
                "elementType": "all",
                "stylers": {
                    "visibility": "off"
                }
            },
            {
                ‘featureType‘: ‘subway‘,
                ‘elementType‘: ‘all‘,
                ‘stylers‘: {
                    "visibility": "off"
                }
            },
            {
                ‘featureType‘: ‘building‘,
                ‘elementType‘: ‘geometry.fill‘,
                ‘stylers‘: {
                    ‘color‘: ‘#000000‘
                }
            },
            {
                ‘featureType‘: ‘all‘,
                ‘elementType‘: ‘labels.text.fill‘,
                ‘stylers‘: {
                    ‘color‘: ‘#857f7f‘
                }
            },
            {
                ‘featureType‘: ‘all‘,
                ‘elementType‘: ‘labels.text.stroke‘,
                ‘stylers‘: {
                    ‘color‘: ‘#000000‘
                }
            },
            {
                ‘featureType‘: ‘building‘,
                ‘elementType‘: ‘geometry‘,
                ‘stylers‘: {
                    ‘color‘: ‘#022338‘
                }
            },
            {
                ‘featureType‘: ‘green‘,
                ‘elementType‘: ‘geometry‘,
                ‘stylers‘: {
                    "visibility": "off"
                }
            },
            {
                ‘featureType‘: ‘boundary‘,
                ‘elementType‘: ‘all‘,
                ‘stylers‘: {
                    ‘color‘: ‘#465b6c‘
                }
            },
            {
                ‘featureType‘: ‘manmade‘,
                ‘elementType‘: ‘all‘,
                ‘stylers‘: {
                    ‘color‘: ‘#022338‘
                }
            },
            {
                ‘featureType‘: ‘label‘,
                ‘elementType‘: ‘all‘,
                ‘stylers‘: {
                    ‘visibility‘: ‘on‘,
                    ‘color‘: ‘#FFF‘
                }
            },
            {
                "featureType": "poilabel",
                "elementType": "all",
                "stylers": {
                    "visibility": "off"
                }
            },
            {
                "featureType": "district",
                "elementType": "labels.text.stroke",
                "stylers": {
                    "visibility": "on"
                }
                }];
            //线条颜色
            var colors = ["#00A0E9", "#F29B76", "#F76B8F", "#6DF3AC", "#CF42E8", "#F1EA24"];
            $(function () {

                //初始化地图
                var bampCharts = echarts.init(document.querySelector("#bMap"));

                options = {
                    backgroupColor:"#091E43",
                    title : {
                        show:false,
                        text: ‘‘,
                        subtext:‘‘,
                        x:‘center‘,
                        textStyle : {
                            color: ‘#fff‘
                        }
                    },
                    tooltip: {
                        trigger: ‘item‘
                    },
                    toolbox: {
                        show: false,
                        right: ‘3%‘,
                        feature: {
                            dataView: {readOnly: false},
                            restore: {},
                            saveAsImage: {}
                        }
                    },
                    bmap:{
                        //定义中心点
                        center: [119.308069,26.087438],
                        zoom: 8,//地图缩放比例
                        roam: true,//开启用户缩放
                        //样式
                        mapStyle: {
                            styleJson: styleJson

                        },
                        series:[{
                            type:‘map‘,
                            mapType:‘china‘,
                            coordinateSystem:‘bmap‘,
                             data:[{
                                        name: ‘福建省‘, value: 20057.34,
                                        label: {
                                            normal: {
                                                show: false,
                                                formatter: function (params) {
                                                    return params.name + "\n" + params.value;    //地图上展示文字 + 数值
                                                },

                                            }
                                        },
                                        itemStyle: {
                                            normal: {
                                                areaColor: ‘#C1FFC1‘     //地图颜色
                                            }
                                        }
                                    }]
                        }]
                    }
                };

                //实例化地图
                bampCharts.setOption(options);

                //地图点线传输动画效果
                //坐标点集合
                var d = [{name:‘清源山‘,longitude:118.618628,latitude:24.957289,isShow:true},
                {name:‘嵩屿电厂‘,longitude:118.034528,latitude:24.45114,isShow:true},
                {name:‘厦门三安光电‘,longitude:118.203815,latitude:24.683459,isShow:true},
                {name:‘龙岩市政府‘,longitude:117.023867,latitude:25.082091,isShow:true},
                {name:‘厦门海沧自贸区‘,longitude:118.032496,latitude:24.476532,isShow:true}];

                var planePath =
                    ‘path://M1705.06,1318.313v-89.254l-319.9-221.799l0.073-208.063c0.521-84.662-26.629-121.796-63.961-121.491c-37.332-0.305-64.482,36.829-63.961,121.491l0.073,208.063l-319.9,221.799v89.254l330.343-157.288l12.238,241.308l-134.449,92.931l0.531,42.034l175.125-42.917l175.125,42.917l0.531-42.034l-134.449-92.931l12.238-241.308L1705.06,1318.313z‘;
                var end = { name: ‘‘, position: [119.308069,26.087438] ,isShow:false};
                var ods = [];
                var marks = [];
                marks.push({
                    name: end.name,
                    isShow: end.isShow,
                    value: end.position.concat([100])
                });

                d.forEach(function(el) {
                    if (!el) return;
                    //描线
                    ods.push({
                        fromName: el.name,
                        toname: end.name,
                        coords: [[el.longitude, el.latitude], end.position]
                    });
                    //定义坐标点
                    marks.push({
                        name: el.name,
                        isShow: el.isShow,
                        value: [el.longitude, el.latitude, 40]
                    });
                });

                options.series = [
                    {
                        type: ‘lines‘,
                        coordinateSystem: ‘bmap‘,
                        zlevel: 2,
                        data: ods,
                        //线上面的动态特效
                        effect: {
                            show: true,
                            period: 6,
                            trailLength: 0.1,
                            symbolSize: 10,
                            symbol: planePath
                        },
                        lineStyle: {
                            normal: {
                                color: function(params) {
                                    return colors[params.dataIndex + 1];
                                },
                                curveness: 0.2
                            }
                        }
                    },
                    {
                        type: ‘effectScatter‘,
                        coordinateSystem: ‘bmap‘,
                        data: marks,
                        symbolSize: function(val) {
                            return val[2] / 5;
                        },
                        showEffectOn: ‘render‘,
                        rippleEffect: {
                            period: 2,
                            brushType: ‘stroke‘,
                            scale: 3
                        },
                        hoverAnimation: true,
                        label: {
                            normal: {
                                formatter: function (params) {
                                    if (params.data.isShow) {
                                        var info = ‘\n {strong1|‘ + params.name + ‘}‘
                                            + ‘\n\n 排放总量:2341.42‘
                                            + ‘\n\n 通讯状态:‘ + ‘{color3|‘ + ‘通讯正常‘ + ‘}‘
                                            + ‘\n\n 设备标识:XM-05-TD‘;    //地图上展示文字 + 数值
                                        return info;
                                    }
                                    else {
                                        return ‘‘;
                                    }
                                },
                                position: [-170,-145],
                                show: true,
                                textStyle: {
                                    color: ‘#fff‘,
                                    size:‘35‘
                                },
                                backgroundColor: {//内容背景图
                                    image: ‘/images/preview/popup.png‘
                                },
                                //自定义控件(由于label无法解析html)
                                rich: {
                                    //设置控件引用名
                                    strong1: {
                                        fontSize: 18,
                                        fontWeight: ‘bold‘,
                                        lineHeight:25
                                    },
                                    color1: {
                                        color:‘#fff701‘//黄色
                                    },
                                    color2: {
                                        color:‘#fe0002‘//红色
                                    },
                                    color3: {
                                        color:‘#18cc47‘//绿色
                                    }
                                },
                                height: 150,
                                width: 220,
                                lineHeight: 12,
                                padding: [5, 10]
                            }
                        },
                        itemStyle: {
                            normal: {
                                color: function(params) {
                                    return colors[params.dataIndex];
                                },
                                shadowBlur: 10,
                                shadowColor: ‘#333‘
                            }
                        },
                        zlevel: 1
                    }
                ];

                //实例化
                bampCharts.setOption(options);
            })

    </script>

里头碰到几个问题:

1.在纯html里头运行无法出现地图

原因:跨域问题(我是放到VS上面运行才出现地图效果的--有经过IIS)

2.echarts.min.js版本问题

3.自定义控件(由于label无法解析html--代码里头已给注释)

原文地址:https://www.cnblogs.com/dzw159/p/11204932.html

时间: 2024-07-31 17:53:46

echarts+百度地图的相关文章

数据视化Echarts+百度地图API实现市县区级下钻

开始 这两天公司有个页面需要做数据可视化的展示,数据视化采用的是Echarts+百度地图API做展示,需要用到县级区级下钻的一个联动效果发现网上关于Echarts做到县区级下钻的资料很少,有的话也不是很详细,对于刚接触Echarts的让人来说可能有些搞不明白,在这里我把Echarts下钻开发过程中总结的知识分享给大家,也能使自己加深印象,当然啦,对于一些在软件行业折腾了几年的老油条来说,这些都是一些非常基础的东西.但是还是希望能帮助到那些刚接触Echarts遇到类似问题需要帮助的人.如果哪里写的

几个不错的echarts +百度地图 案例

https://echarts.baidu.com/examples/editor.html?c=map-polygon https://echarts.baidu.com/examples/editor.html?c=effectScatter-bmap 空气质量等,可以通过值来控制点的大小和光环. https://echarts.baidu.com/examples/editor.html?c=heatmap-bmap 人流密度图.热力图等 我的echarts+百度地图 左上角可以切换地图和

百度地图、ECharts整合HT for Web网络拓扑图应用

直击现场 百度地图.ECharts整合HT for Web网络拓扑图应用 发表于3周前(2015-03-23 01:32)   阅读(1320) | 评论(5) 78人收藏此文章, 我要收藏 赞8 慕课网,程序员升职加薪神器,点击免费学习 摘要 前一篇谈及到了ECharts整合HT for Web的网络拓扑图应用,后来在ECharts的Demo中看到了有关空气质量的相关报表应用,就想将百度地图.ECharts和HT for Web三者结合起来也做一个类似空气质量报告的报表+拓扑图应用. high

Winform Echarts 显示百度地图的用法(3)

1,用Echarts 显示百度地图的用法(2)写一个 baidu.html 2,winform页面放一个WebBrowser控件,用来放地图的html页面 3,winform 加载时 将WebBrowser文件放在baidu.html同一个目录下 webBrw_Map.Url = new Uri(Path.Combine(Application.StartupPath, "baidumap.html")); 4,加载地图 (1),根据经纬度查询 var pointX = "3

Echarts 结合百度地图使用总结

注:echarts结合china.js使用效果并不好,china.js是矢量图,显示的地图只有一个轮廓,所以正常会选择百度地图或者其他地图配合使用. 一.代码如下(参考网上,并加入自己的整理) function initHotMap(dataArr, domId, title){ $.get("${ctxStatic}/resources/js/bmap/dataTool.js",function(){ $.get('${ctxStatic}/resources/js/bmap/bma

Echarts 显示百度地图的用法(2)

<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=vgQfNjTQDlCar24CrTIdWcwY"></script> <div id="allmap" style="height: 600px"></div><br/> <span id="ln

echarts移除百度地图logo方法

移除百度地图LOGO和版权信息 在jsp头上加上如下代码即可: <style type="text/css"> .anchorBL{ display:none } </style> 原文地址:https://www.cnblogs.com/XiOrang/p/9895444.html

百度地图公交线路查询,并绘制到地图上并获取所有路径经纬度点(可供echarts 路径图使用)

github地址 https://github.com/a1115040996/MyHTML/tree/gh-pages/BDMap 源代码 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.o

用百度地图API分析打交通大数据

百度地图API, 文档不全,例子不细致. 在网上还没有太多有用的例子.比如说下面几个需求的解决方案就找不到: 1. 如何用百度地图API查询一个地点的经纬度. 2. 如何用百度地图通过一个经纬度查询商圈和地址. 3.点击百度地图时, 获得点击位置的经纬度. 4. 如果按照时间轴动态显示热力图的变化. 我昨天玩了一下午百度地图javascript API,解决了上面的几个问题,顺道用少量打车用户的抽样数据做一个数据可视化, 给大家提供一个可以参考的例子 首先数据是来自北京市某个周日的出行数据, 其