-
-
Notifications
You must be signed in to change notification settings - Fork 937
Expand file tree
/
Copy pathImageScaleTests.tsx
More file actions
124 lines (114 loc) · 3.01 KB
/
ImageScaleTests.tsx
File metadata and controls
124 lines (114 loc) · 3.01 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
import {
Images,
MapView,
ShapeSource,
SymbolLayer,
Camera,
CircleLayer,
} from '@rnmapbox/maps';
import { type ComponentProps } from 'react';
import { View, Image, Text, type ImageSourcePropType } from 'react-native';
const styles = {
mapView: { flex: 1 },
} as const;
const iconLayerStyle: ComponentProps<typeof SymbolLayer>['style'] = {
iconSize: 1.0,
iconImage: ['get', 'icon'],
textField: ['get', 'text'],
textColor: 'black',
textHaloColor: 'white',
textHaloWidth: 1,
textAnchor: 'top',
textOffset: [0, 2.5] as number[],
} as const;
const dx = 0.005;
const dy = 0.005;
function feature(image: string, x: number, y: number): GeoJSON.Feature {
return {
type: 'Feature',
id: `feature-${image}-${x}-{y}`,
geometry: {
type: 'Point',
coordinates: [-74.00597 + x * dx, 40.71427 + y * dy],
},
properties: {
icon: image,
text: `${image}`,
},
};
}
const features: GeoJSON.FeatureCollection = {
type: 'FeatureCollection',
features: [
feature('icon1', 0, 0),
feature('icon2', 1, 0),
feature('icon3', 0, 1),
feature('icon4', 1, 1),
feature('bicon1', 1, 2),
],
};
const baseImages: {
[key: string]: ImageSourcePropType;
} = {
icon1: require('../../assets/scale-test-icon.png'),
icon2: require('../../assets/scale-test-icon2.png'),
icon3: require('../../assets/scale-test-icon3.png'),
icon4: require('../../assets/scale-test-icon4.png'),
} as const;
const scaleImages: {
[key: string]: { image: ImageSourcePropType; scale: number };
} = {
bicon1: {
image: require('../../assets/scale-test-icon.png'),
scale: 1.0,
},
} as const;
const allImages = { ...baseImages, ...scaleImages };
const ImageScaleTests = () => {
const radius = 32;
const circelStyle = {
circleRadius: radius,
circleOpacity: 0.4,
circleStrokeColor: 'green',
circleStrokeWidth: 2,
};
return (
<>
<View
style={{
flexDirection: 'row',
padding: 4,
justifyContent: 'space-around',
}}
>
{Object.entries(baseImages).map(([key, value]) => (
<View
key={key}
style={{ flexDirection: 'column', alignItems: 'center' }}
>
<Image key={key} source={value} />
<Text>{key}</Text>
</View>
))}
{Object.entries(scaleImages).map(([key, value]) => (
<View
key={key}
style={{ flexDirection: 'column', alignItems: 'center' }}
>
<Image source={value.image} />
<Text>{key}</Text>
</View>
))}
</View>
<MapView style={styles.mapView}>
<Camera centerCoordinate={[-74.00597, 40.71427]} zoomLevel={14} />
<Images images={allImages} />
<ShapeSource id={'shape-source-id-0'} shape={features}>
<SymbolLayer id="symbol-id" style={iconLayerStyle} />
<CircleLayer id="circel-layer" style={circelStyle} />
</ShapeSource>
</MapView>
</>
);
};
export default ImageScaleTests;