简体   繁体   English

如何在 mapbox GL 上将样式设置为图像模式

[英]How to Set Style to image pattern on mapbox GL

Hi i'm creating bus and subway routing using mapbox and react - i need different color for my pattern that drawing line on the map you can see my sample pattern on image below嗨,我正在使用 mapbox 创建公共汽车和地铁路线并做出反应 - 我的图案需要不同的颜色,在 map 上绘制线你可以在下图中看到我的示例图案

look at my pattern image看看我的图案图片

as you can see pattern has static color (green) i need to set this color dynamically with hex code that return from server.如您所见,模式具有 static 颜色(绿色)我需要使用从服务器返回的十六进制代码动态设置此颜色。

if wrote function for get pattern如果为获取模式写了 function

 getPattern(type, section_type, index, line_name) { if (section_type === routingTypes.METRO) { switch (line_name) { case '1': return pattern_metro_1; case '2': return pattern_metro_1; case '3': return [pattern_metro_1, '#00B8F8']; case '4': return '<img src={pattern_metro_1} style="border: 3px solid green" />'; case '5': return pattern_metro_1; case '6': return pattern_metro_1; case '7': return pattern_metro_1; default: return pattern_metro_1; } } }

as you can see all cases are static pattern image but i need some thing like case 3 that i set image and pattern and image fill with that color.如您所见,所有案例都是 static 图案图像,但我需要像案例 3 这样的东西,我设置图像和图案以及用该颜色填充的图像。 also i tried case 4 but it doesn't work either.我也尝试了案例 4,但它也不起作用。

I think it fails because you are using ' wrongly,我认为它失败了,因为你使用错误,

Try this尝试这个

case '4':
  return '<img src={pattern_metro_1} style="border: 3px solid green" />';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM