ol Map 测距完整例示 仿百度测距

效果图:

 


//********************************************************测距**start**
//加载测量的绘制矢量层
var source = new ol.source.Vector(); //图层数据源
var vector = new ol.layer.Vector({
    source: source,
    style: new ol.style.Style({ //图层样式
        fill: new ol.style.Fill({
            color: 'rgba(255, 255, 255, 0.2)' //填充颜色
        }),
        stroke: new ol.style.Stroke({
            color: '#ffcc33', //边框颜色
            width: 2 // 边框宽度
        }),
        image: new ol.style.Circle({
            radius: 7,
            fill: new ol.style.Fill({
                color: '#ffcc33'
            })
        })
    })
});
map.addLayer(vector);

/**
 * 帮助提示框对象(The help tooltip element.)
 * @type {Element}
 */
var helpTooltipElement;
/**
 *帮助提示框显示的信息(Overlay to show the help messages.)
 * @type {ol.Overlay}
 */
var helpTooltip;
/**
 * 测量工具提示框对象(The measure tooltip element. )
 * @type {Element}
 */
var measureTooltipElement;
/**
 *测量工具中显示的测量值(Overlay to show the measurement.)
 * @type {ol.Overlay}
 */
var measureTooltip;


var draw; // global so we can remove it later
/**
 * 加载交互绘制控件函数
 */
function addInteraction() {
    var type = 'LineString';
    var timestamp = new Date().getTime();
    draw = new ol.interaction.Draw({
        source: source, //测量绘制层数据源
        type: /** @type {ol.geom.GeometryType} */ (type), //几何图形类型
        style: new ol.style.Style({ //绘制几何图形的样式
            fill: new ol.style.Fill({
                color: 'rgba(255, 255, 255, 0.2)'
            }),
            stroke: new ol.style.Stroke({
                color: 'rgba(0, 0, 0, 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值