• 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
      }
    
  • 相关阅读:
    多项式 Wannafly挑战赛22
    L. Twice Equation ACM Nanning 2017
    我们身边的大数据
    js_隔10秒发送验证码(setInterrval定时器)
    js_定时器(setInterval)
    VS调试相关
    afx_msg与消息映射机制
    ON_COMMAND,ON_MESSAGE和ON_NOTIFY的区别
    条款4:确定对象在被使用前已经被初始化
    用doxygen+graphviz生成函数调用流程图
  • 原文地址:https://www.cnblogs.com/wwj007/p/11857818.html
Copyright © 2020-2023  润新知