如何使用SVG图像作为mapbox的基础地图?
我知道,OpenLayers和传单为开发人员提供了这样的机会。
传单:
var svgUrl = 'image.svg',
imageBounds = [[0, 0], [100, 100]];
L.imageOverlay(svgUrl , imageBounds).addTo(map);
OpenLayers:
var svgUrl = 'image.svg',
var imgLayer = new ImageLayer({
source: new Static({
url: svgUrl,
projection: projection,
imageExtent: extent,
imageLoadFunction: function (image, src) {
image.getImage().src = src;
image.getImage().width = olExtent.getWidth(extent);
image.getImage().height = olExtent.getHeight(extent);
},
}),
});
map.addLayer(imgLayer);
AFAIK,mapbox GL JS也可以处理图像覆盖:
var svgUrl = 'image.svg',
this.map.addSource("myImageSource", {
type: "image",
url: svgUrl,
coordinates: [
[-80.425, 46.437],
[-71.516, 46.437],
[-71.516, 37.936],
[-80.425, 37.936],
],
});
map.addLayer({
id: "overlay",
source: "myImageSource",
type: "raster",
paint: { "raster-opacity": 0.85 },
});
但!如果我试图加载svg,则会得到以下错误:
错误:无法加载映像,因为源映像无法解码。请确保使用支持的图像类型,如PNG或JPEG。请注意,不支持SVG。
那么,有什么办法来处理这个问题呢?
https://stackoverflow.com/questions/63920189
复制