forked from kusamakura/react-native-gmaps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Polyline.js
64 lines (52 loc) · 1.27 KB
/
Polyline.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
'use strict';
let React = require('react-native');
let {
NativeModules
} = React;
var API = NativeModules.RNGMapsPolylineModule;
class Polyline {
static create(options, callback) {
Object.assign(options||{}, {
name: this.constructor.name
});
options.points = options.points || [];
API.create(options, function(id) {
callback(new Polyline(id, options));
});
}
constructor (id, config) {
this.id = id;
this.color = config.color;
this.points = config.points || [];
this.width = config.width;
}
addPoint(lat, lng, callback) {
callback = callback || (()=>{});
this.points.push([lat, lng]);
API.setState(this._toMap(), callback);
}
setPoints(points, callback) {
callback = callback || (()=>{});
API.setState(this._toMap(), callback);
}
setState(config, callback) {
callback = callback || (()=>{});
Object.assign(this, config);
API.setState(this._toMap(), callback);
}
remove(callback) {
callback = callback || (()=>{});
API.remove(this.id, callback);
}
_toMap() {
return {
id: this.id,
color: this.color,
geodesic: this.geodesic,
visible: this.visible,
width: this.width,
points: this.points
}
}
}
module.exports = Polyline;