Skip to content

Commit 7037dc7

Browse files
committed
【feature】 L7图层更新
1 parent 21c855d commit 7037dc7

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

src/mapboxgl/mapping/utils/L7LayerUtil.js

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ const StyleRenderType = {
170170
fillExtrusion: 'fillExtrusion'
171171
};
172172

173+
const L7_WIDTH_MULTIPLE = 0.5;
174+
173175
/**
174176
* @param {string} url
175177
* @param {string} [token]
@@ -1123,7 +1125,7 @@ function transformWebmapLineLayerToSceneLayer(layer, source, map) {
11231125
type: MSLayerType.line,
11241126
source,
11251127
color: expressionToFunction({ value: color, property: 'color', map }),
1126-
size: expressionMultiToFunction(map, { value: width }, { value: height }),
1128+
size: expressionMultiToFunction(map, { value: width, multiple: L7_WIDTH_MULTIPLE }, { value: height }),
11271129
shape: {
11281130
values: 'line'
11291131
},
@@ -1506,13 +1508,29 @@ function imgDataToBlob(imagedata) {
15061508
return image.src;
15071509
}
15081510

1511+
/**
1512+
* 将雪碧图1倍地址替换成2x的
1513+
*/
1514+
function replaceSprite2X(url) {
1515+
const arrs = url.split('/');
1516+
const lastSprite = arrs.slice(-1)[0];
1517+
if (!lastSprite) {
1518+
return url;
1519+
}
1520+
const newLastSprite = lastSprite.replace('sprite', 'sprite@2x');
1521+
arrs.splice(arrs.length - 1, 1, newLastSprite);
1522+
return arrs.join('/');
1523+
}
1524+
15091525
/**
15101526
* 根据设备比返回对应的Url
15111527
* @param url sprite url
15121528
*/
15131529
function getPixelRatioSpriteUrl(url) {
1514-
const format = window.devicePixelRatio > 1 ? '@2x' : '';
1515-
return url + format;
1530+
if (window.devicePixelRatio > 1 && !url.includes('/sprite@2x')) {
1531+
return replaceSprite2X(url);
1532+
}
1533+
return url;
15161534
}
15171535

15181536
function getSpritePngUrl(spriteUrl) {
@@ -1576,7 +1594,7 @@ async function addTextures({ layers, sprite, spriteJson, scene, options }) {
15761594
const iconInfo = spriteJson[texture];
15771595
if (iconInfo) {
15781596
const image = await changeSpriteIconToImgData(
1579-
getPixelRatioSpriteUrl(sprite),
1597+
sprite,
15801598
{ ...iconInfo, id: texture },
15811599
options
15821600
);

0 commit comments

Comments
 (0)