Mapv 添加自定义图形扇形

4 篇文章 0 订阅
3 篇文章 1 订阅

1、效果



2、修改源码

在 pathSimple 对象 draw 方法下 'Point' 里添加 自定义 symbol类型

添加红框内的代码,给定自定义图形的类型名称,当前例子 “sector”
代码:

if (symbol === 'sector') {
    context.arc(coordinates[0], coordinates[1], size, 0, 60 * Math.PI / 180);
    context.lineTo(coordinates[0] - size * Math.cos(60 * Math.PI / 180), coordinates[1] - size * Math.sin(60 * Math.PI / 180));
    context.arc(coordinates[0], coordinates[1], size, 240 * Math.PI / 180, 300 * Math.PI / 180);
    context.lineTo(coordinates[0] - size * Math.cos(60 * Math.PI / 180), coordinates[1] + size * Math.sin(60 * Math.PI / 180));
    context.arc(coordinates[0], coordinates[1], size, 120 * Math.PI / 180, 180 * Math.PI / 180);
    context.lineTo(coordinates[0] + size, coordinates[1]);
}

3、如何使用
 

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <title>
    </title>
    <style type="text/css">
        html, body {
            width: 100%;
            height: 100%;
            margin: 0;
            padding: 0;
            overflow: hidden;
        }

        #map {
            width: 100%;
            height: 100%;
        }
    </style>
</head>
<body>
<div id="map">
</div>
<canvas id="canvas"></canvas>
<script src="http://api.map.baidu.com/api?v=2.0&ak=?????" type="text/javascript"></script>
<script src="mapv.js" type="text/javascript"></script>
<script type="text/javascript">
    // 百度地图API功能
    var map = new BMap.Map("map", {
        enableMapClick: false
    });    // 创建Map实例
    map.centerAndZoom(new BMap.Point(113.802075, 23.071224), 9);  // 初始化地图,设置中心点坐标和地图级别
    map.enableScrollWheelZoom(true); // 开启鼠标滚轮缩放


    var randomCount = 10;
    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 - 1 + Math.random() * 2, cityCenter.lat - 1 + Math.random() * 2]
            },
            count: 30 * Math.random()
        });
    }

    var dataSet = new mapv.DataSet(data);

    var options = {
        // unit: 'm',
        size: 30,
        symbol: 'sector', // 核心,自定义的类型就在这里配置
        fillStyle: 'rgba(0, 0, 0, 0)', // 填充颜色
        strokeStyle: 'red', // 描边颜色
        lineWidth: 2, // 描边宽度
        draw: 'simple',
        methods: {
            click: function (item) {
                console.log(item);
            }
        },
    };

    var mapvLayer = new mapv.baiduMapLayer(map, dataSet, options);
</script>
</body>
</html>



 

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值