>我在地图上有数千个注释。每个注释都是一个唯一的图像。因此,除非用户要求,否则我不想在地图上加载所有图像。
我的批注具有以下属性:
detailCalloutView: <Image source={{uri: data[i].img_url, cache: 'force-cache'}} style={styles.thumbnail} resizeMode={Image.resizeMode.contain}/>
如何使图像仅在打开注释时加载?我不想通过打开所有注释来粉碎千兆字节的数据。
我想我需要对onFocus
做点什么,但我不太确定如何做。
更改此内容
detailCalloutView: <Image source={{uri: data[i].img_url, cache: 'force-cache'}} style={styles.thumbnail} resizeMode={Image.resizeMode.contain}/>
对此
detailCalloutView: <Image source="blanking.jpg" data-annotation={{uri: data[i].img_url, cache: 'force-cache'}} style={styles.thumbnail} resizeMode={Image.resizeMode.contain}/>
然后将事件侦听器添加到地图中的所有图像
var attr = this.getAttribute("data-annotation");
this.src = attr;
这是要补充的主要部分。现在即使关闭,它也不必再次加载,因为src
将永远是实际图像。我不会为你包装整个JavaScript,但你应该从中得到要点。