Skip to content

Commit bfa32a7

Browse files
committed
[example] 修改maplibregl例子中loadImage逻辑
1 parent effefaf commit bfa32a7

File tree

2 files changed

+31
-16
lines changed

2 files changed

+31
-16
lines changed

examples/maplibregl/01_chartService.html

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -643,11 +643,16 @@ <h5 class='panel-title text-center'>
643643
}
644644
}
645645

646-
map.loadImage(
647-
'../img/point2.png',
648-
function(error, image) {
649-
if (error) throw error;
650-
map.addImage('icon_name', image);
646+
// maplibre-gl v3版本用法:
647+
// map.loadImage(
648+
// '../img/point2.png',
649+
// function(error, image) {
650+
// if (error) throw error;
651+
// map.addImage('icon_name', image);
652+
// });
653+
// maplibre-gl v4版本用法:
654+
map.loadImage('../img/point2.png').then(function(image) {
655+
map.addImage('icon_name', image.data);
651656
});
652657
function sqlQuery() {
653658
var chartLayerNames = document.getElementById("chartLayers").value;

examples/maplibregl/mvtVectorTile_poi_highlight.html

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,27 @@
4747
maxZoom:12,
4848
crs: maplibregl.CRS.EPSG4326
4949
});
50-
map.on('load', function () {
51-
map.loadImage('../img/poi-bg.png', function (error, image) {
52-
if (error) throw error;
53-
if (!map.hasImage('poi-bg')) {
54-
map.addImage('poi-bg', image, {
55-
stretchX: [[14, 190]],
56-
stretchY: [[14, 90]],
57-
content: [14, 14, 190, 90],
58-
pixelRatio: 1
59-
});
60-
}
50+
map.on('load', async function () {
51+
// maplibre-gl v3版本用法:
52+
// map.loadImage('../img/poi-bg.png', function (error, image) {
53+
// if (error) throw error;
54+
// if (!map.hasImage('poi-bg')) {
55+
// map.addImage('poi-bg', image, {
56+
// stretchX: [[14, 190]],
57+
// stretchY: [[14, 90]],
58+
// content: [14, 14, 190, 90],
59+
// pixelRatio: 1
60+
// });
61+
// }
62+
// });
63+
64+
// maplibre-gl v4版本用法:
65+
const image = await map.loadImage('../img/poi-bg.png');
66+
map.addImage('poi-bg', image.data,{
67+
stretchX: [[14, 190]],
68+
stretchY: [[14, 90]],
69+
content: [14, 14, 190, 90],
70+
pixelRatio: 1
6171
});
6272
map.addLayer(
6373
{

0 commit comments

Comments
 (0)