vue+svg实现按等级缩放的路线组件

1.先看效果

 a.这个是一级效果

b.二级效果

2.代码实现

a.完整代码示例

<template>
  <div>
    <div class="route-preview" :style="{ ...styleExternalIcon }">
      <!-- <div style="margin-top: -20px;float: left;white-space: nowrap;margin-right:4px;">{
  { tunnelEnterance }}
      </div> -->
      <div style="margin-top: -20px;float: left;margin-right:4px; min-width: 80px; max-width: 80px; word-break: break-word; white-space: normal;max-height: 60px;">{
  { tunnelEnterance }}</div>

      <!-- <div class="road-name">康护理大道</div> -->
      <div class="legend" ref="legendContainer">
        <svg ref="svgElement" :width="tunnelWidth" :key="this.key" :height="60" style="margin-bottom: -8px;">
          <defs>
        <pattern id="image" x="0" y="0" width="100%" height="100%">
          <image
            x="0"
            y="0"
            :width="localLineLength"
            :height="lineHeight"
            href="../../assets/crop/tunnelWire.png"
            preserveAspectRatio="none"
          />
        </pattern>
      </defs>

      <!-- 使用图案填充矩形 -->
      <rect x="0" y="20" :width="localLineLength" :height="lineHeight" fill="url(#image)" />
          <!-- 绘制蓝色覆盖区域 -->
          <template v-for="(item, index) in this.tempList">
            <rect v-if="item.endStation >= item.startStation" :x="scaleValue3(item.startStation,item.startCode)" :y="20"
              :width="scaleValue3(item.endStation,item.endCode) - scaleValue3(item.startStation,item.startCode)" :height="lineHeight" fill="#9b99f9"
              :key="'rect1-' + index" />
            <rect v-else :x="scaleValue3(item.endStation,item.endCode)" :y="20"
              :width="scaleValue3(item.startStation,item.startCode) - scaleValue3(item.endStation,item.endCode)" :height="lineHeight" fill="#000080"
              :key="'rect-' + index" />
          </template>
          <!-- 绘制圆形节点 -->
          <image v-for="(node, index) in nodes" :key="'image-no' + index" :x="scaleValue(node.cx)"
            :y="lineHeight / 1 - nodeRadius + 16" :width="nodeRadius * 2"
            xlink:href="../../assets/crop/pointWhite.png" />
          <image v-for="(node, index) in nodes" :key="'image-' + index" v-if="isNodeInCoverage(node)"
            :x="scaleValue(node.cx)" :y="lineHeight / 1 - nodeRadius + 16" :width="nodeRadius * 2"
             xlink:href="../../assets/crop/pointPurple.png" />
          <!-- 告警节点 -->
          <!-- <image style="cursor: pointer;" v-for="(node, index) in alarmNodes" :key="'image1-' + index"
            v-if="node.type == 0" @click="openAlarmInfo(node.id)" :x="scaleValue3(node.cx,node.code) - nodeRadius"
            :y="lineHeight / 1 - nodeRadius + 16" :width="nodeRadius * 2" :height="nodeRadius * 2"
            xlink:href="../../assets/crop/pointYellow.png" />
          <image style="cursor: pointer;" v-for="(node, index) in alarmNodes" :key="'image2-' + index"
            @click="openAlarmInfo(node.id)" v-if="node.type == 1&
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值