-
Notifications
You must be signed in to change notification settings - Fork 1
/
arrival_shapes_layer.js
65 lines (57 loc) · 1.48 KB
/
arrival_shapes_layer.js
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
import React, {Component} from "react";
import {Platform, StyleSheet, Text, View} from "react-native";
import {connect} from "react-redux";
import Mapbox from "@mapbox/react-native-mapbox-gl";
import {lineString} from "@turf/helpers";
import {MIN_LABEL_LAYER_ID, EXCLUDE_ALL, INCLUDE_ALL} from "./constants";
function tripShape(selectedArrival) {
let trip =
selectedArrival && selectedArrival.item && selectedArrival.item.trip_shape;
if (!trip) {
return {
type: "FeatureCollection",
features: []
};
}
return {
type: "Feature",
properties: {
color: "#" + trip.color,
route_id: trip.route_id
},
geometry: {
type: "LineString",
coordinates: trip.points.map(p => [p.lng, p.lat])
}
};
}
function ArrivalShapesLayer(props) {
const {selectedArrival} = props;
return (
<Mapbox.ShapeSource
id="arrival_shapes_source"
shape={tripShape(selectedArrival)}>
<Mapbox.LineLayer
id="arrival_shapes_layer"
belowLayerID={MIN_LABEL_LAYER_ID}
style={[
mapStyles.layer,
{visibility: selectedArrival ? "visible" : "hidden"}
]}
/>
</Mapbox.ShapeSource>
);
}
function mapStateToProps(state) {
return {
selectedArrival: state.selectedArrival
};
}
export default connect(mapStateToProps)(ArrivalShapesLayer);
const mapStyles = Mapbox.StyleSheet.create({
layer: {
lineColor: Mapbox.StyleSheet.identity("color"),
lineOpacity: 1,
lineWidth: 3
}
});