注册自定义材质实现qgis里不同比例尺下材质不被拉升的效果

前景提要:

在QGIS里的显示效果,用的是示例的/img/textures/line-interval.png材质图片。

下载示例

git clone https://gitee.com/marsgis/mars3d-vue-example.git

相关效果

比如材质是5像素,在1:100000万比例尺下,线显示的长度是5像素,那就用一个材质显示,如果放大到1:10000比例尺,线显示的长度是50像素,那就用10个材质显示,这样材质就不会被拉伸了

polyline的宽度及材质均是像素参数,通过自定义材质的方法实现以下效果。

高视角下:

低视角下:

 示例链接:

功能示例(Vue版) | Mars3D三维可视化平台 | 火星科技

实现代码:

function addDemoGraphic11(graphicLayer) {
  // 注册自定义材质
  const MianmianType = "LineSprite"
  mars3d.MaterialUtil.register(MianmianType, {
    fabric: {
      uniforms: {
        image: Cesium.Material.DefaultImageId,
        imageW: 10
      },
      source: `
    in float v_polylineAngle;
    mat2 rotate(float rad) {
        float c = cos(rad);
        float s = sin(rad);
        return mat2(
            c, s,
            -s, c
        );
    }
    czm_material czm_getMaterial(czm_materialInput materialInput)
      {
        czm_material material = czm_getDefaultMaterial(materialInput);
        vec2 st = materialInput.st;
        vec2 pos = rotate(v_polylineAngle) * gl_FragCoord.xy;
        float s = pos.x / (imageW * czm_pixelRatio);
        float t = st.t;
        vec4 colorImage = texture(image, vec2(fract(s), t));
        material.diffuse = colorImage.rgb;
        return material;
      }`
    },
    translucent: true
  })
  const graphic = new mars3d.graphic.PolylinePrimitive({
    positions: [
      [116.295277, 30.98],
      [116.295277, 31],
      [116.4, 31]
    ],
    style: {
      width: 10,
      clampToGround: true,
      // 使用自定义材质
      materialType: MianmianType,
      materialOptions: {
        image: "./img/textures/line-interval.png",
        imageW: 74
      }
    },
    flyTo:true
  })
  graphicLayer.addGraphic(graphic)
}

实现效果:

 

相关推荐

  1. uni-app定义导航栏刷新实现

    2024-06-08 13:56:07       15 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-06-08 13:56:07       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-06-08 13:56:07       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-06-08 13:56:07       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-06-08 13:56:07       18 阅读

热门阅读

  1. 林锐C语言--高质量C/C++编程(第五六章)

    2024-06-08 13:56:07       7 阅读
  2. kotlin调用类文件

    2024-06-08 13:56:07       6 阅读
  3. Kotlin 运算符重载

    2024-06-08 13:56:07       8 阅读
  4. Kotlin 引用(双冒号::)

    2024-06-08 13:56:07       7 阅读
  5. Nginx配置负载均衡

    2024-06-08 13:56:07       6 阅读
  6. git commit rule

    2024-06-08 13:56:07       9 阅读
  7. C# WPF入门学习主线篇(五)—— Button的事件

    2024-06-08 13:56:07       11 阅读
  8. spark第一篇简介

    2024-06-08 13:56:07       8 阅读