* @function WebSymbol.prototype.getSymbol * @param {string} id - 符号ID。 * @description 获取符号信息。 * @returns {object} 符号信息。 * @private
(id, map)
| 307 | * @private |
| 308 | */ |
| 309 | async function getSymbol(id, map) { |
| 310 | let url = `${map.basePath}/${id}/${id}`; |
| 311 | if (process.env.NODE_ENV === 'development') { |
| 312 | url = `../../dist/resources/symbols/${id}/${id}`; |
| 313 | } |
| 314 | |
| 315 | const value = await FetchRequest.get(`${url}.json`).then(response => { |
| 316 | if (!response.ok) { |
| 317 | return null; |
| 318 | } |
| 319 | return response.json(); |
| 320 | }) |
| 321 | .catch(() => null); |
| 322 | if (!value) { |
| 323 | return null; |
| 324 | } |
| 325 | const paint = value.paint || {}; |
| 326 | const layout = value.layout || {}; |
| 327 | const hasImage = paint['fill-pattern'] || paint['line-pattern'] || layout['icon-image']; |
| 328 | const image = hasImage && await new Promise((resolve) => { |
| 329 | const image = new Image(); |
| 330 | image.src = `${url}.png`; |
| 331 | image.onload = (content) => { |
| 332 | resolve(content ? image : null); |
| 333 | }; |
| 334 | image.onerror = () => { |
| 335 | resolve(null); |
| 336 | }; |
| 337 | }); |
| 338 | return { |
| 339 | value, |
| 340 | image |
| 341 | } |
| 342 | } |
| 343 | |
| 344 | /** |
| 345 | * 加载单个Web符号 |