mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-26 05:15:49 +08:00
Added support for custom color and image for map annotations
Summary: public This diff extends RCTMap annotations with an `image` and `tintColor` property, which can be used to render completely custom pin graphics. The tintColor applies to both regular pins and custom pin images, allowing you to provide varied pin colors without needing multiple graphic assets. Reviewed By: fredliu Differential Revision: D2685581 fb-gh-sync-id: c7cf0af5c90fd8d1e9b3fec4b89206440b47ba8f
This commit is contained in:
committed by
facebook-github-bot-5
parent
63ef826d44
commit
5b5b55027b
@@ -149,9 +149,6 @@ var MapViewExample = React.createClass({
|
||||
|
||||
getInitialState() {
|
||||
return {
|
||||
mapRegion: null,
|
||||
mapRegionInput: null,
|
||||
annotations: null,
|
||||
isFirstLoad: true,
|
||||
};
|
||||
},
|
||||
@@ -163,12 +160,12 @@ var MapViewExample = React.createClass({
|
||||
style={styles.map}
|
||||
onRegionChange={this._onRegionChange}
|
||||
onRegionChangeComplete={this._onRegionChangeComplete}
|
||||
region={this.state.mapRegion || undefined}
|
||||
annotations={this.state.annotations || undefined}
|
||||
region={this.state.mapRegion}
|
||||
annotations={this.state.annotations}
|
||||
/>
|
||||
<MapRegionInput
|
||||
onChange={this._onRegionInputChanged}
|
||||
region={this.state.mapRegionInput || undefined}
|
||||
region={this.state.mapRegionInput}
|
||||
/>
|
||||
</View>
|
||||
);
|
||||
@@ -208,6 +205,114 @@ var MapViewExample = React.createClass({
|
||||
|
||||
});
|
||||
|
||||
var CalloutMapViewExample = React.createClass({
|
||||
|
||||
getInitialState() {
|
||||
return {
|
||||
isFirstLoad: true,
|
||||
};
|
||||
},
|
||||
|
||||
render() {
|
||||
if (this.state.isFirstLoad) {
|
||||
var onRegionChangeComplete = (region) => {
|
||||
this.setState({
|
||||
isFirstLoad: false,
|
||||
annotations: [{
|
||||
longitude: region.longitude,
|
||||
latitude: region.latitude,
|
||||
title: 'More Info...',
|
||||
hasRightCallout: true,
|
||||
onRightCalloutPress: () => {
|
||||
alert('You Are Here');
|
||||
},
|
||||
}],
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
return (
|
||||
<MapView
|
||||
style={styles.map}
|
||||
onRegionChangeComplete={onRegionChangeComplete}
|
||||
region={this.state.mapRegion}
|
||||
annotations={this.state.annotations}
|
||||
/>
|
||||
);
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
var CustomPinColorMapViewExample = React.createClass({
|
||||
|
||||
getInitialState() {
|
||||
return {
|
||||
isFirstLoad: true,
|
||||
};
|
||||
},
|
||||
|
||||
render() {
|
||||
if (this.state.isFirstLoad) {
|
||||
var onRegionChangeComplete = (region) => {
|
||||
this.setState({
|
||||
isFirstLoad: false,
|
||||
annotations: [{
|
||||
longitude: region.longitude,
|
||||
latitude: region.latitude,
|
||||
title: 'You Are Purple',
|
||||
tintColor: MapView.PinColors.PURPLE,
|
||||
}],
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
return (
|
||||
<MapView
|
||||
style={styles.map}
|
||||
onRegionChangeComplete={onRegionChangeComplete}
|
||||
region={this.state.mapRegion}
|
||||
annotations={this.state.annotations}
|
||||
/>
|
||||
);
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
var CustomPinImageMapViewExample = React.createClass({
|
||||
|
||||
getInitialState() {
|
||||
return {
|
||||
isFirstLoad: true,
|
||||
};
|
||||
},
|
||||
|
||||
render() {
|
||||
if (this.state.isFirstLoad) {
|
||||
var onRegionChangeComplete = (region) => {
|
||||
this.setState({
|
||||
isFirstLoad: false,
|
||||
annotations: [{
|
||||
longitude: region.longitude,
|
||||
latitude: region.latitude,
|
||||
title: 'Thumbs Up!',
|
||||
image: require('image!uie_thumb_big'),
|
||||
}],
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
return (
|
||||
<MapView
|
||||
style={styles.map}
|
||||
onRegionChangeComplete={onRegionChangeComplete}
|
||||
region={this.state.mapRegion}
|
||||
annotations={this.state.annotations}
|
||||
/>
|
||||
);
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
var styles = StyleSheet.create({
|
||||
map: {
|
||||
height: 150,
|
||||
@@ -249,5 +354,23 @@ exports.examples = [
|
||||
render() {
|
||||
return <MapView style={styles.map} showsUserLocation={true} />;
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
title: 'Callout example',
|
||||
render() {
|
||||
return <CalloutMapViewExample style={styles.map} />;
|
||||
}
|
||||
},
|
||||
{
|
||||
title: 'Custom pin color',
|
||||
render() {
|
||||
return <CustomPinColorMapViewExample style={styles.map} />;
|
||||
}
|
||||
},
|
||||
{
|
||||
title: 'Custom pin image',
|
||||
render() {
|
||||
return <CustomPinImageMapViewExample style={styles.map} />;
|
||||
}
|
||||
},
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user