在Mapbox中添加图像-来源如何?

问题描述 投票:0回答:1

我想在我在地图框中准备的图像中添加图像。我阅读了文档,但问题是我找不到如何将图像从PC上传到mapbox的方法,因为在所有示例中,似乎都有通过mapbox获取图像的源。我可以将图像上传到mapbox中的某个地方吗?如果没有,还有什么其他解决方案?

javascript image datasource mapbox-gl-js mapbox-studio
1个回答
0
投票

我们可能会遇到语言障碍,但是您是否要问如何在Mapbox Studio之外向地图添加图像?如果是这样,这是我用于天气应用程序的示例。注意,我将其设置为“隐藏”,但是您可以根据需要进行修改。目前,我没有时间为您做很多修改,但是您正在问“有关来源”的问题,下面有一个解决方案。希望这可以满足您的需求。我添加了一些评论。

 map.on('load', function() {
          map.addSource("source_KEWX_L3_KDP", {   // adding a source
            "type": "image", // specify type
            "url": "images/KEWX_L3_KDP.gif", // URL
            "coordinates": [

[-102, 33],  
[-94, 33],   
[-94, 26], 
[-102, 26]      
        ]
      })



// The following code places the image underneath my labels, this is not required.
var layers = map.getStyle().layers;
    // Find the index of the first symbol layer in the map style
    var firstSymbolId;
    for (var i = 0; i < layers.length; i++) {
        if (layers[i].type === 'symbol') {
            firstSymbolId = layers[i].id;
            break;
        }
    }

      map.addLayer({ // Now we add the layer we created previously
        "id": "overlay_KEWX_L3_KDP",
        "source": "source_KEWX_L3_KDP",
        "type": "raster",
"layout": {"visibility": "hidden"},
   "paint": {

    "raster-fade-duration": 0
  },




      }, firstSymbolId)
    });
© www.soinside.com 2019 - 2024. All rights reserved.