 


$(function () { 
  
    echart_map();
    function echart_map() {
        // 基于准备好的dom，初始化echarts实例
        
      
        var myChart = echarts.init(document.getElementById('ceshi8'));
	
	
 
	
	
	
        var chinaGeoCoordMap = {
            
            'NEW JCM': [116.4551, 40.2539], 
          "Russia": [37.35,55.45],
			  "Singapore":[103.87546,1.30243],
			  "Trinidad and Tobago":[-60.32,11.18],
              "Uae": [54.22,24.28],
           'North Africa': [17.228331,26.3351],
           "West Africa": [-13.49,9.29],
          	 "Central Asia": [71.30,51.10],
           "USA": [-82.32,33.01],
           "Canada": [-90.32,50.01]
			 

        };
        var chinaDatas = [
		//[{
        //        name: 'Russia',
        //        value: 1,
		//		num:'1家'
        //    }]
			
			//,[{
              //  name: 'NEW JCM',
              //  value: 1,
			//	num:'1家'
           // }]
			
			[{
                name: 'USA',
                value: 1,
				num:'1家'
            }],[{
                name: 'Canada',
                value: 1,
				num:'1家'
            }],[{
                name: 'Central Asia',
                value: 1,
				num:'1家'
            }],[{
                name: 'Singapore',
                value: 1,
				num:'1家'
            }],[{
                name: 'West Africa',
                value: 1,
				num:'1家'
            }],[{
                name: 'North Africa',
                value: 1,
				num:'1家'
            }]
			,[{
                name: 'Trinidad and Tobago',
                value: 1,
				num:'1家'
            }],[{
                name: 'Uae',
                value: 1,
				num:'1家'
            }] 
        ];

        var convertData = function(data) {
            var res = [];
            for(var i = 0; i < data.length; i++) {
                var dataItem = data[i];
                var fromCoord = [116.4551, 40.2539];
                var toCoord = chinaGeoCoordMap[dataItem[0].name];
                if(fromCoord && toCoord) {
                    res.push([{
                        coord: fromCoord,
                        value: dataItem[0].value
                    }, {
                        coord: toCoord,
                    }]);
					
                }
            }
            return res;
        };
        var series = [];
        [['NEW JCM', chinaDatas]].forEach(function(item, i) {
            console.log(item)
			
			
 
			
			
            series.push({
                    type: 'lines',
                    zlevel: 2,
                    effect: {
                        show: true,
                        period: 4, //箭头指向速度，值越小速度越快
                        trailLength: 0.02, //特效尾迹长度[0,1]值越大，尾迹越长重
                        symbol: 'arrow', //箭头图标
                        symbolSize: 10, //图标大小
                    },
                    lineStyle: {
                        normal: {
                            width: 0.2, //尾迹线条宽度
                            opacity: 0.5, //尾迹线条透明度
                            curveness: 0.4 //尾迹线条曲直度
                        }
                    },
                    data: convertData(item[1])
                }, {
                    type: 'effectScatter',
                    coordinateSystem: 'geo',
                    zlevel: 2,
                    rippleEffect: { //涟漪特效
                        period: 4, //动画时间，值越小速度越快
                        brushType: 'stroke', //波纹绘制方式 stroke, fill
                        scale: 4 //波纹圆环最大限制，值越大波纹越大
                    },
                    label: {
                        normal: {
                            show: true,
                            position: 'right', //显示位置
                            offset: [5, 0], //偏移设置
                            formatter: function(params){//圆环显示文字
                                return params.data.name;
                            },
                            fontSize: 15,
                            textShadowColor: 'rgba(0, 0, 0, 0.5)', // 文字阴影颜色
                            textShadowBlur: 10 // 文字阴影模糊度
                        },
                        emphasis: {
                            show: true
                        }
                    },
                    symbol: 'circle',
                    symbolSize: function(val) {
                        return 5+ val[2] * 5; //圆环大小
                    },
                    itemStyle: {
                        normal: {
                            show: false,
                            color: '#e01f22'
                        }
                    },
                    data: item[1].map(function(dataItem) {
                        return {
                            name: dataItem[0].name,
                            value: chinaGeoCoordMap[dataItem[0].name].concat([dataItem[0].value])
                        };
                    }),
                },
                //被攻击点
                {
                    type: 'scatter',
                    coordinateSystem: 'geo',
                    zlevel: 2,
                    rippleEffect: {
                        period: 4,
                        brushType: 'stroke',
                        scale: 4
                    },
                    label: {
                        normal: {
                            show: true,
                            position: 'right',
                            //offset:[5, 0],
                            color: '#D32222',
                            formatter: '{b}',
                            textStyle: {
                                color: "#FDD774",
                                fontSize: 18,
                               textShadowColor: 'rgba(0, 0, 0, 0.5)', // 文字阴影颜色
                            textShadowBlur: 10 // 文字阴影模糊度
                            }
                        },
                        emphasis: {
                            show: true,
                            color: "#D32222"
                        }
                    },
                    symbol: 'pin',
                    symbolSize: 50,
                    data: [{
                        name: item[0],
                        value: chinaGeoCoordMap[item[0]].concat([10]),
                    }],
                }
            );
        });

        option = {
            tooltip: {
                trigger: 'item',
                backgroundColor: '#e01f22',
                borderColor: '#e01f22',
                showDelay: 0,
                hideDelay: 0,
                enterable: true,
                transitionDuration: 0,
                extraCssText: 'z-index:100',
				 //根据业务自己拓展要显示的内容
                formatter: function(params, ticket, callback) {
                    var res = "";
                    var name = params.name;
                    var value = params.value[params.seriesIndex + 1];
					var num = params.num;
                    res = '';
					// "<span style='color:#fff;'>" + name + "</span><br/>门店：" + value
                    return res;
                }
            },
			
			// 添加图形元素，在地图上方叠图片
    graphic: {
        elements: [
            {
                type: 'image',
                style: {
                    image: 'https://omo-oss-image.thefastimg.com/portal-saas/pg2024080812023427043/cms/image/fd0d10a2-3cf8-4c94-a840-f056f3654f0f.jpg', // 背景图片的 URL
                    width: 1200, // 背景图片的宽度，根据需要调整
                    height: 600 // 背景图片的高度，根据需要调整
                },
                left: 'center', // 图片位置，居中
                top: 'center' // 图片位置，居中
            }
        ]
    },
			
			
			
            /*backgroundColor:"#013954",*/
            visualMap: { //图例值控制
                min: 0,
                max: 2,
                calculable: true,
                show: false,
                color: ['#FDD774', '#FDD774', '#FDD774', '#fff', '#fff'],
                textStyle: {
                    color: '#fff'
                }
            },
            geo: {
                map: 'world',
                zoom: 1.2,
                label: {
                    emphasis: {
                        show: false
                    }
                },
                roam: false, //是否允许缩放
                itemStyle: {
                    normal: {
                        color: 'rgba(0, 0, 0, 0)', //地图背景色
                        borderColor: 'rgba(0, 0, 0, 0)', //省市边界线00fcff 516a89
                        borderWidth: 0
                    },
                    emphasis: {
                        color: 'rgba(0, 0, 0, 0)' //悬浮背景
                    }
                }
            },
            series: series
        };
        // 使用刚指定的配置项和数据显示图表。
        myChart.setOption(option);
        window.addEventListener("resize",function(){
            myChart.resize();
        });

    }

})



