zoukankan      html  css  js  c++  java
  • vue项目使用openlayers来添加地图标注,标注样式设置的简要模板

    先把代码贴出来,注释以后有时间再写(需要留意一下这里图标的引入方式,函数内相同路径无法找到图片)

    import sk from "../../assets/img/home/sk-active.png";
    import hd from "../../assets/img/home/river-active.png";
    
      // 雨量站  状态:颜色标识 点
      switch (status) {
        case 0: status = '#a8eba8'
          break;
        case 1: status = '#69befe'
          break;
        case 2: status = '#ea29fb'
          break;
        case 3: status = '#ea29fb'
          break;
      }
      function style(names) {
        return new Style({
          image: names === 'yl' ? new Circle({
            radius: 5,
            fill: new Fill({
              color: '#05ab57',
            }),
            stroke: new Stroke({
              color: status,
               16
            }),
          }) : new Icon({
            anchor: [0.5, 30],
            anchorOrigin: 'bottom-right',
            anchorXUnits: 'fraction',
            anchorYUnits: 'pixels',
            scale: 0.45,
            src: names === 'sk' ? sk : hd,
          }),
          text: new Text({
            textAlign: "center", // 位置
            textBaseline: "center", // 基准线
            offsetX: 0,
            offsetY: 30,
            text: name,
            fill: new Fill({
              color: "#333",// 文本填充样式(即文字颜色)
            }),
            stroke: new Stroke({
              color: "#Fff",
            }),
            zIndex: 9
          })
        })
      }
      var ylStyle = style('yl')
      var skStyle = style('sk')
      var hdStyle = style('hd')
    
      // var ylStyle = new Style({
      //   image: new Circle({
      //     radius: 5,
      //     fill: new Fill({
      //       color: '#05ab57',
      //     }),
      //     stroke: new Stroke({
      //       color: status,
      //        16
      //     }),
      //   }),
      //   text: new Text({
      //     textAlign: "center", // 位置
      //     textBaseline: "top", // 基准线
      //     offsetX: 0,
      //     offsetY: 20,
      //     text: name,
      //     fill: new Fill({
      //       color: "#000",// 文本填充样式(即文字颜色)
      //     }),
      //     stroke: new Stroke({
      //       color: "#Fff",
      //        1,
      //     }),
      //     zIndex: 9
      //   })
      // })
    
      // // 水库    点
      // var skStyle = new Style({
      //   image: new Icon({
      //     anchor: [0.5, 30],
      //     anchorOrigin: 'bottom-right',
      //     anchorXUnits: 'fraction',
      //     anchorYUnits: 'pixels',
      //     // offsetOrigin: 'bottom-center',
      //     scale: 0.45,
      //     src: sk,
    
      //   }),
      //   text: new Text({
      //     textAlign: "center", // 位置
      //     textBaseline: "center", // 基准线
      //     offsetX: 0,
      //     offsetY: 30,
      //     // font: "normal 12px 微软雅黑", // 文字样式
      //     text: name,
      //     fill: new Fill({
      //       color: "#333",// 文本填充样式(即文字颜色)
      //     }),
      //     stroke: new Stroke({
      //       color: "#Fff",
      //     }),
      //     zIndex: 9
      //   })
      // })
    
      // // 河道    点
      // var hdStyle = new Style({
      //   image: new Icon({
      //     anchor: [0.5, 26],
      //     anchorXUnits: 'fraction',
      //     anchorYUnits: 'pixels',
      //     scale: 0.48,
      //     src: hd,
      //   }),
      //   text: new Text({
      //     textAlign: "center", // 位置
      //     textBaseline: "center", // 基准线
      //     offsetX: 0,
      //     offsetY: 30,
      //     // font: "normal 12px 微软雅黑", // 文字样式
      //     text: name,
      //     fill: new Fill({
      //       color: "#333",// 文本填充样式(即文字颜色)
      //     }),
      //     stroke: new Stroke({
      //       color: "#Fff",
      //     }),
      //     zIndex: 9
      //   })
      // })
      return {
        ylStyle,
        skStyle,
        hdStyle
      }
    
  • 相关阅读:
    RecyclerView与各种异步图片加载框架不兼容的问题
    课内上机实验3——括号匹配(栈)
    课内上机实验3——删除重复元素
    课内上机实验3——数组内移动0元素至末尾
    课内上机实验3——M集合问题(队列)
    递归实践1——Cnm组合数计算
    【转】Quine的编写
    【转】fork函数详解
    【转】Makefile详解
    VC++6.0程序安装
  • 原文地址:https://www.cnblogs.com/wwj007/p/11857818.html
Copyright © 2011-2022 走看看