如何根据 Azure 地图中事件中的警告添加丢失的图像"styleimagemissing"?以及如何找出缺少哪些图像/图标?



我添加了许多从imageSprite.createFromTemplate((方法创建的图标,但有时我会收到以下错误。如何使用";styleimagemissing";事件如何找出要添加到回调中的缺少的图像?。在某些簇中,使用图标创建的符号层有时也会重叠在气泡层(簇层(上。我不知道这是否是由于图像丢失造成的。提前谢谢。

atlas.min.js:55 Image "Scaffold Builder_Inactive_Icon" could not be loaded. Please make sure you have added the image with map.addImage() or a "sprite" property in your style. You can provide missing images by listening for the "styleimagemissing" map event.

styleimagemissing事件将告诉您丢失的图像的ID。它不会告诉你哪个符号层试图使用该图像,但单个图像可能被多个层使用。

以下是如何使用此事件的示例:

var iconLoaded = {};
//Add an event to handle the situation when an image is missing from the sprite.
map.events.add('styleimagemissing', function (id) {
//Check to see if the image is has been or is being loaded. Don't try and load the image multiple times.
if (!iconLoaded[id]) {
iconLoaded[id] = true;
//Load the custom image icon into the map resources.
map.imageSprite.add(id, '../Common/images/icons/showers.png').then();
}
});

完整的样本可在此处获得:https://github.com/Azure-Samples/AzureMapsCodeSamples/blob/master/AzureMapsCodeSamples/Symbol%20Layer/Load%20missing%20image%20into%20sprite.html

最新更新