GIS工具maptalks开发手册(二)02——渲染线

GIS工具maptalks开发手册(二)02——渲染线

效果

在这里插入图片描述

1、html版本

LineString.html

<!DOCTYPE html>
<html>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>图形 - LineString</title>
<style type="text/css">
    html,
    body {
        margin: 0px;
        height: 100%;
        width: 100%;
    }

    .container {
        width: 900px;
        height: 500px;
        margin: 50px;
    }
</style>
<link rel="stylesheet" href="https://unpkg.com/maptalks/dist/maptalks.css">
<script type="text/javascript" src="https://unpkg.com/maptalks/dist/maptalks.min.js"></script>

<body>

    <div id="map" class="container"></div>

    <script>
        var map = new maptalks.Map('map', {
            center: [-0.113049, 51.498568],
            zoom: 14,
            baseLayer: new maptalks.TileLayer('base', {
                urlTemplate: 'https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png',
                subdomains: ['a', 'b', 'c', 'd'],
                attribution: '&copy; <a href="http://osm.org">OpenStreetMap</a> contributors, &copy; <a href="https://carto.com/">CARTO</a>'
            })
        });

        var line = new maptalks.LineString([
            [-0.131049, 51.498568],
            [-0.107049, 51.498568]
        ], {
            arrowStyle: null, // arrow-style : now we only have classic  箭头样式:现在我们只有经典
            // 箭头位置
            arrowPlacement: 'vertex-last', // arrow's placement: vertex-first, vertex-last, vertex-firstlast, point
            visible: true, // 可见的
            editable: true, // 可编辑的
            cursor: null, // 光标
            shadowBlur: 0, // 阴影模糊
            shadowColor: 'black', // 阴影颜色
            draggable: false, // 是否可拖动
            // 拖动阴影 
            dragShadow: false, // display a shadow during dragging (拖动时显示阴影)
            // 轴上绘图
            drawOnAxis: null,  // force dragging stick on a axis, can be: x, y (轴上的力拖动杆,可以是:x,y)
            symbol: {
                'lineColor': '#1bbc9b',
                'lineWidth': 3
            }
        });

        new maptalks.VectorLayer('vector', line).addTo(map);

    </script>
</body>

</html>
2、vue版本
<template>
  <!-- maptalks渲染线 -->
  <div id="map" class="container"></div>
</template>
<script>
import "maptalks/dist/maptalks.css";
import * as maptalks from "maptalks";
export default {
  mounted() {
    this.$nextTick(() => {
      this.init();
    });
  },
  methods: {
    init() {
       var map = new maptalks.Map('map', {
            center: [-0.113049, 51.498568],
            zoom: 14,
            baseLayer: new maptalks.TileLayer('base', {
                urlTemplate: 'https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png',
                subdomains: ['a', 'b', 'c', 'd'],
                attribution: '&copy; <a href="http://osm.org">OpenStreetMap</a> contributors, &copy; <a href="https://carto.com/">CARTO</a>'
            })
        });

        var line = new maptalks.LineString([
            [-0.131049, 51.498568],
            [-0.107049, 51.498568]
        ], {
            arrowStyle: null, // arrow-style : now we only have classic  箭头样式:现在我们只有经典
            // 箭头位置
            arrowPlacement: 'vertex-last', // arrow's placement: vertex-first, vertex-last, vertex-firstlast, point
            visible: true, // 可见的
            editable: true, // 可编辑的
            cursor: null, // 光标
            shadowBlur: 0, // 阴影模糊
            shadowColor: 'black', // 阴影颜色
            draggable: false, // 是否可拖动
            // 拖动阴影 
            dragShadow: false, // display a shadow during dragging (拖动时显示阴影)
            // 轴上绘图
            drawOnAxis: null,  // force dragging stick on a axis, can be: x, y (轴上的力拖动杆,可以是:x,y)
            symbol: {
                'lineColor': '#1bbc9b',
                'lineWidth': 3
            }
        });

        new maptalks.VectorLayer('vector', line).addTo(map);

    },
  },
};
</script>
<style lang="scss">
html,
body {
  margin: 0px;
  height: 100%;
  width: 100%;
}
.container {
  width: 1200px;
  height: 700px;
  margin: 50px;
}
</style>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值