当前位置: 首页 > article >正文

leaflet对线设置渐变色

效果展示:

 引用leaflet-polycolor组件

npm install leaflet-polycolor

.vue文件中使用 

import leafletPolycolor from 'leaflet-polycolor';

leafletPolycolor(L);

const latLngs = [[37.03, 111.92], [37.53444, 111.98555], [36.88, 112.12], [37.53444, 112.24], [36.88, 112.54], [37.45, 112.74]];

  const colors = ['rgb(20, 200, 100)', 'rgb(200, 100, 20)', null, null, 'rgb(20, 200, 100)', 'rgb(0, 0, 0)'];

  L.polycolor(latLngs, {

    color: "#ff0000",

    colors: colors,

    weight: 5

  }).addTo(map);

完整代码:

<template>
  <div class="h-full">
    <div class="h-full w-full" id="map"></div>
  </div>
</template>

<script setup lang="ts">
import {ref, onMounted} from "vue";
import L from "leaflet";
import "leaflet.chinatmsproviders";

import leafletPolycolor from 'leaflet-polycolor';
leafletPolycolor(L);

function init() {
  const TDT_KEY = "天地图上面获取key";
  const normalm = L.tileLayer.chinaProvider("TianDiTu.Normal.Map", {
    key: TDT_KEY,
    maxZoom: 18,
    minZoom: 5,
  });
  const normala = L.tileLayer.chinaProvider("TianDiTu.Normal.Annotion", {
    key: TDT_KEY,
    maxZoom: 18,
    minZoom: 5,
  });
  const imgm = L.tileLayer.chinaProvider("TianDiTu.Satellite.Map", {
    key: TDT_KEY,
    maxZoom: 24,
    maxNativeZoom: 18,
    minZoom: 5,
  });
  const imga = L.tileLayer.chinaProvider("TianDiTu.Satellite.Annotion", {
    key: TDT_KEY,
    maxZoom: 24,
    maxNativeZoom: 18,
  });
  const normal = L.layerGroup([normalm, normala]);
  const image = L.layerGroup([imgm, imga]);
  const baseLayers = {
    地图: normal,
    影像: image,
  };
  // 初始化 map
  var map = new L.Map('map', {
    maxZoom: 24,
    minZoom: 5,
    center: [37.03, 111.92],
    zoom: 16,
    zoomControl: false,
    renderer: L.canvas({ tolerance: 16 }),
    layers: [normal],
  });
  L.control.layers(baseLayers, {}).addTo(map).setPosition("topleft");
  L.control.zoom().addTo(map).setPosition("topleft");
  L.circle([37.03, 111.92], { radius: 100, color: "#ff0000", weight: 5, fill: true, fillColor: "#00ff00", fillOpacity: 1 }).addTo(map);

  const latLngs = [[37.03, 111.92], [37.53444, 111.98555], [36.88, 112.12], [37.53444, 112.24], [36.88, 112.54], [37.45, 112.74]];
  const colors = ['rgb(20, 200, 100)', 'rgb(200, 100, 20)', null, null, 'rgb(20, 200, 100)', 'rgb(0, 0, 0)'];

  L.polycolor(latLngs, {
    color: "#ff0000",
    colors: colors,
    weight: 5
  }).addTo(map);
}

onMounted(() => {
  init();
})
</script>

<style lang="scss" scoped>

</style>

注意:如果线两端点没有渲染,则线显示颜色为配置color颜色,不为渐变色。 

 


http://www.kler.cn/news/148885.html

相关文章:

  • LLM大语言模型
  • 深入redis过程-命令
  • 代码随想录算法训练营第四十九天【动态规划part10】 | 121. 买卖股票的最佳时机、122.买卖股票的最佳时机II
  • Android:从源码看FragmentManager如何工作
  • Python内置类属性`__name__`属性的使用教程
  • WPF中DataGrid解析
  • Webshell混淆免杀的一些思路
  • 成绩排序(练习链表)
  • 《数据结构、算法与应用C++语言描述》-二叉树与其他树-二叉树的C++实现-设置信号放大器与并查集问题
  • Positive Technologies 公司发布了一种保护容器环境的产品 PT Container Security
  • Android 13 - Media框架(14)- OpenMax(四)
  • 开源C++智能语音识别库whisper.cpp开发使用入门
  • Pytest自动化测试框架完美结合Allure
  • 微服务--05--配置管理
  • 大模型训练为什么用A100不用4090
  • Python编写的爬虫为什么受欢迎?
  • 【PHP】MySQL简介与MySQLi函数(含PHP与MySQL交互)
  • Android手电筒、闪光灯、torch、flash
  • CMake中的变量: CTest,CPack,CMake内部定义的变量
  • 封装websocket并在vuejs中调用
  • 动态库与静态库
  • Python与设计模式--设计原则
  • 九、LuaTable(表)
  • Nginx访问控制
  • 力扣142. 环形链表 II
  • 面试问题--智能指针
  • linux网络编程之UDP编程
  • 详细讲解1.js处理日期对象输出标准的“2000年12月22日 周三“ 的格式
  • 杂记 | 使用Docker安装并配置MongoDB以支持事务(单副本,并解决了证书文件错误的问题)
  • centos7.9 + gitlab12.3.0安装