首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >React Native Maps - Callout不显示内部图像

React Native Maps - Callout不显示内部图像
EN

Stack Overflow用户
提问于 2019-06-28 22:31:42
回答 2查看 1.1K关注 0票数 0

当我尝试在React Native Maps标注中渲染图像时遇到问题。

图像不会渲染。

代码语言:javascript
复制
{this.state.database.map((route, idx) => {
        if (route.Image) {
          return (
            <MapView.Marker
              coordinate={{ latitude: Number.parseFloat(route.Latitude), longitude: Number.parseFloat(route.Longitude) }}
              key={idx}
              image={img_pin}
              ref={(ref) => this.marker = ref}
            >
              <MapView.Callout tooltip style={{ flex: 1, backgroundColor: 'white' }}>
                <View style={{ flexDirection: 'row' }}>
                  <View style={{ flex: 1 }}>
                    <Text style={styles.textCallout}>Latitude: {route.Latitude}</Text>
                    <Text style={styles.textCallout}>Longitude: {route.Longitude}</Text>
                    <Text style={styles.textCallout}>Status: <Icon name={route.Status === 1 ? 'checkmark-circle' : 'close-circle'} style={{ color: route.Status === 1 ? 'green' : 'red', fontSize: 16 }} /> </Text>
                    <Text style={styles.textCallout}>Velocidade: {route.Speed} km/h</Text>
                  </View>
                  <View style={{ margin: 5 }}>
                    <Image source={{ uri: `data:image/gif;base64,${route.Image}` }} style={{ width: 150, height: 100 }} />
                  </View>
                </View>
              </MapView.Callout>
            </MapView.Marker>
          );
        }
      })}

Image error don't render inside Callout

代码语言:javascript
复制
"react-native": "^0.57.8",
"react-native-maps": "^0.24.2",
EN

回答 2

Stack Overflow用户

发布于 2020-03-23 19:36:29

在文本组件中使用图像

代码语言:javascript
复制
<Text> <Image style={{ height: 100, width:100 }} source={{ ... }} resizeMode="cover" /> </Text>

另一种解决方法是使用WebView。我认为这是目前最合适的解决方案。

代码语言:javascript
复制
<View>
  <WebView style={{ height: 100 , width: 230, }} source={{ uri: ... }} />
</View>
票数 1
EN

Stack Overflow用户

发布于 2019-06-29 00:14:35

确保您的route.image是url模式的形式,

exampleData

代码语言:javascript
复制
 source={{uri: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADMAAAAzCAYAAAA6oTAqAAAAEXRFWHRTb2Z0d2FyZQBwbmdjcnVzaEB1SfMAAABQSURBVGje7dSxCQBACARB+2/ab8BEeQNhFi6WSYzYLYudDQYGBgYGBgYGBgYGBgYGBgZmcvDqYGBgmhivGQYGBgYGBgYGBgYGBgYGBgbmQw+P/eMrC5UTVAAAAABJRU5ErkJggg=='}}

如果正确,

安卓上的

GIF和WebP支持

在构建自己的原生代码时,安卓系统默认不支持GIF和WebP。

您将需要在android/app/build.gradle中添加一些可选模块,具体取决于应用程序的需求。

build.gradle:

代码语言:javascript
复制
dependencies {
  // If your app supports Android versions before Ice Cream Sandwich (API level 14)
  implementation 'com.facebook.fresco:animated-base-support:1.10.0'

  // For animated GIF support
  implementation 'com.facebook.fresco:animated-gif:1.10.0'

  // For WebP support, including animated WebP
  implementation 'com.facebook.fresco:animated-webp:1.10.0'
  implementation 'com.facebook.fresco:webpsupport:1.10.0'

  // For WebP support, without animations
  implementation 'com.facebook.fresco:webpsupport:1.10.0'
}

用法

代码语言:javascript
复制
  <MapView.Callout tooltip={true} style={{ backgroundColor: 'white', height: contentHeight, width: contentWidth }}>
                <View style={{ flexDirection: 'column' }}>
                  <View style={{ flex: 1 }}>
                    <Text style={styles.textCallout}>Latitude: {route.Latitude}</Text>
                    <Text style={styles.textCallout}>Longitude: {route.Longitude}</Text>
                    <Text style={styles.textCallout}>Status: <Icon name={route.Status === 1 ? 'checkmark-circle' : 'close-circle'} style={{ color: route.Status === 1 ? 'green' : 'red', fontSize: 16 }} /> </Text>
                    <Text style={styles.textCallout}>Velocidade: {route.Speed} km/h</Text>
                  </View>
                 <Image source={{ uri: `data:image/gif;base64,${route.Image}` }} style={{ width: 150, height: 100, resizeMode="cover" }} />
                </View>
              </MapView.Callout>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56808780

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档