Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

在使用ImageLayer时,layer.source传入svg格式的图片时,这个图片图层展示不出来,png的可以。 #1865

Closed
zimutao opened this issue Sep 13, 2023 · 7 comments
Assignees
Labels
good first issue Good for newcomers

Comments

@zimutao
Copy link

zimutao commented Sep 13, 2023

问题描述:在使用ImageLayer时,layer.source传入svg格式的图片时,这个图片图层展示不出来,png的可以。

https://codesandbox.io/s/xenodochial-cartwright-jqlqfj?from-embed
代码:

 const scene = new Scene({
      id: "map",
      map: new GaodeMap({
        pitch: 0,
        style: "light",
        center: [121.168, 30.2828],
        zoom: 14.89,
        minZoom: 10
      })
    });
    fetch(
      "https://gw.alipayobjects.com/os/basement_prod/893d1d5f-11d9-45f3-8322-ee9140d288ae.json"
    )
      .then((res) => res.json())
      .then((data) => {
        const layer = new ImageLayer({});
        layer.source(
          "1.svg",
          {
            parser: {
              type: "image",
              extent: [121.168, 30.2828, 121.384, 30.4219]
            }
          }
        );

        scene.addLayer(layer);
      });
@github-actions
Copy link
Contributor

hi @zimutao, welcome!

@github-actions
Copy link
Contributor

Hi @zimutao, Please star this repo if you find it useful! Thanks ⭐!
你好 @zimutao。如果该仓库对你有用,可以 star 一下,感谢你的 ⭐!

@github-actions github-actions bot added the good first issue Good for newcomers label Sep 13, 2023
@lzxue
Copy link
Contributor

lzxue commented Sep 13, 2023

支持 SVG 的,访问的你的图片链接访问不了

@zimutao
Copy link
Author

zimutao commented Sep 13, 2023

支持 SVG 的,访问的你的图片链接访问不了

我没描述清楚,png和svg都是本地文件,直接引入后,png可以展示。这种场景,用这个api或者其他api可以实现吗?
image

@lzxue
Copy link
Contributor

lzxue commented Sep 13, 2023

可能是打包的问题,你可以尝试 实例化成 image 对象看看

@zimutao
Copy link
Author

zimutao commented Sep 14, 2023

可能是打包的问题,你可以尝试 实例化成 image 对象看看

初始化可以加载出来,之后的热更新或者再次添加一个图层会出现错误。
image
image

@zimutao zimutao closed this as completed Sep 14, 2023
@zimutao
Copy link
Author

zimutao commented Sep 14, 2023

可能是打包的问题,你可以尝试 实例化成 image 对象看看

实例化就好了,上个问题是图片没加载完成我就传入了,加上img.onload就好了。
感谢回复。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants