-
-
Notifications
You must be signed in to change notification settings - Fork 937
Expand file tree
/
Copy pathShapeSourceIcon.tsx
More file actions
executable file
·179 lines (167 loc) · 4.04 KB
/
ShapeSourceIcon.tsx
File metadata and controls
executable file
·179 lines (167 loc) · 4.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
import React from 'react';
import {
MapView,
Images,
Camera,
Image,
SymbolLayer,
ShapeSource,
} from '@rnmapbox/maps';
import { type StyleProp, Text, type ViewStyle } from 'react-native';
import { type FeatureCollection } from 'geojson';
import exampleIcon from '../../assets/example.png';
import pinIcon from '../../assets/pin.png';
import { type SymbolLayerStyleProps } from '../../../../src/utils/MapboxStyles';
import { type ExampleWithMetadata } from '../common/ExampleMetadata';
const styles: {
icon: SymbolLayerStyleProps;
matchParent: StyleProp<ViewStyle>;
} = {
icon: {
iconImage: ['get', 'icon'],
iconSize: [
'match',
['get', 'icon'],
'example',
1.2,
'airport-15',
1.2,
/* default */ 1,
],
iconAllowOverlap: true,
},
matchParent: { flex: 1 },
};
const featureCollection: FeatureCollection = {
type: 'FeatureCollection',
features: [
{
type: 'Feature',
id: '9d10456e-bdda-4aa9-9269-04c1667d4552',
properties: {
icon: 'example',
},
geometry: {
type: 'Point',
coordinates: [-117.20611157485, 52.180961084261],
},
},
{
type: 'Feature',
id: '9d10456e-bdda-4aa9-9269-04c1667d4552',
properties: {
icon: 'airport-15',
},
geometry: {
type: 'Point',
coordinates: [-117.205908, 52.180843],
},
},
{
type: 'Feature',
id: '9d10456e-bdda-4aa9-9269-04c1667d4552',
properties: {
icon: 'pin',
},
geometry: {
type: 'Point',
coordinates: [-117.206562, 52.180797],
},
},
{
type: 'Feature',
id: '9d10456e-bdda-4aa9-9269-04c1667d4553',
properties: {
icon: 'pin3',
},
geometry: {
type: 'Point',
coordinates: [-117.206862, 52.180897],
},
},
{
type: 'Feature',
id: '9d10456e-bdda-4aa9-9269-04c1667d4555',
properties: {
icon: 'pin-rn',
},
geometry: {
type: 'Point',
coordinates: [-117.205862, 52.180697],
},
},
],
};
class ShapeSourceIcon extends React.Component {
state = {
images: {
example: exampleIcon,
},
};
render() {
const { images } = this.state;
return (
<MapView style={styles.matchParent}>
<Camera
defaultSettings={{
zoomLevel: 16,
centerCoordinate: [-117.20611157485, 52.180961084261],
}}
/>
<Images
nativeAssetImages={['pin']}
images={images}
onImageMissing={(imageKey) => {
if (imageKey !== 'pin-rn') {
this.setState({
images: { ...this.state.images, [imageKey]: pinIcon },
});
}
}}
>
<Image name="pin-rn">
<Text
style={{
fontWeight: 'bold',
textAlign: 'center',
color: 'white',
borderRadius: 10,
backgroundColor: 'gray',
padding: 8,
margin: 16,
width: 100,
shadowOffset: { width: 0, height: 8 },
shadowOpacity: 0.2,
}}
>
RN Pin 3
</Text>
</Image>
</Images>
<ShapeSource id="exampleShapeSource" shape={featureCollection}>
<SymbolLayer id="exampleIconName" style={styles.icon} />
</ShapeSource>
</MapView>
);
}
}
export default ShapeSourceIcon;
/* end-example-doc */
const metadata: ExampleWithMetadata['metadata'] = {
title: 'Shape Source Icons',
tags: [
'ShapeSource',
'SymbolLayer',
'Images',
'Images#nativeAssetImages',
'Images#onImageMissing',
],
docs: `
Render icons with various methods.
* pin-rn: Rendered with a React Native View
* pin: Rendered with a native asset image
* pin3: Resolved as a result of onImageMissing
* example: Rendered with a js asset image (require)
`,
};
(ShapeSourceIcon as unknown as ExampleWithMetadata).metadata = metadata;