@kizmann/pico-js 0.3.10 → 0.3.16
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/pico-js.js +1 -1
- package/dist/pico-js.js.map +1 -1
- package/package.json +1 -1
- package/src/library/map.js +23 -6
- package/src/utility/array.js +1 -11
- package/src/utility/dom.js +1 -1
- package/src/utility/number.js +39 -7
- package/src/utility/object.js +1 -11
package/package.json
CHANGED
package/src/library/map.js
CHANGED
@@ -16,6 +16,8 @@ export default class Map
|
|
16
16
|
|
17
17
|
cluster = null;
|
18
18
|
|
19
|
+
clusterFilter = null;
|
20
|
+
|
19
21
|
clusterOptions = {};
|
20
22
|
|
21
23
|
static hideMarkers = true;
|
@@ -46,7 +48,7 @@ export default class Map
|
|
46
48
|
return this;
|
47
49
|
}
|
48
50
|
|
49
|
-
static setMarkerStyle(key, style = {})
|
51
|
+
static setMarkerStyle(key, style = {}, extra = {})
|
50
52
|
{
|
51
53
|
if ( ! Obj.has(style, 'default') ) {
|
52
54
|
return console.error('Marker style requires default property')
|
@@ -91,12 +93,16 @@ export default class Map
|
|
91
93
|
final.active = final.default;
|
92
94
|
}
|
93
95
|
|
96
|
+
Obj.each(extra, (value, prop) => {
|
97
|
+
final[prop] = Obj.assign({}, final.default, { url: value });
|
98
|
+
});
|
99
|
+
|
94
100
|
Obj.set(Map.markerStyles, key, final);
|
95
101
|
|
96
102
|
return this;
|
97
103
|
}
|
98
104
|
|
99
|
-
clusterMarkers(options = {}, allowCreate = true)
|
105
|
+
clusterMarkers(options = {}, filter = null, allowCreate = true)
|
100
106
|
{
|
101
107
|
if ( ! this.cluster && ! allowCreate ) {
|
102
108
|
return;
|
@@ -111,11 +117,22 @@ export default class Map
|
|
111
117
|
}
|
112
118
|
|
113
119
|
if ( this.cluster ) {
|
114
|
-
this.cluster.clearMarkers()
|
120
|
+
this.cluster.clearMarkers();
|
121
|
+
}
|
122
|
+
|
123
|
+
if ( Any.isFunction(filter) ) {
|
124
|
+
this.clusterFilter = filter;
|
115
125
|
}
|
116
126
|
|
117
127
|
let markers = Arr.filter(this.markers, (item) => {
|
118
|
-
|
128
|
+
|
129
|
+
let visible = this.getMarkerVisibility(item.key);
|
130
|
+
|
131
|
+
if ( ! Any.isFunction(this.clusterFilter) ) {
|
132
|
+
return visible;
|
133
|
+
}
|
134
|
+
|
135
|
+
return visible && this.clusterFilter.call(this, item);
|
119
136
|
});
|
120
137
|
|
121
138
|
this.cluster = new global.MarkerClusterer(this.map, Arr.each(markers, (item) => item.marker),
|
@@ -361,7 +378,7 @@ export default class Map
|
|
361
378
|
|
362
379
|
Obj.set(this.markers, key, item);
|
363
380
|
|
364
|
-
this.clusterMarkers(this.clusterOptions, false);
|
381
|
+
this.clusterMarkers(this.clusterOptions, null, false);
|
365
382
|
|
366
383
|
if ( ! Obj.has(options, 'html') ) {
|
367
384
|
return Obj.get(this.markers, key);
|
@@ -449,7 +466,7 @@ export default class Map
|
|
449
466
|
|
450
467
|
Obj.each(markers, (item) => this.showMarker(item.key));
|
451
468
|
|
452
|
-
this.clusterMarkers(this.clusterOptions, false);
|
469
|
+
this.clusterMarkers(this.clusterOptions, null, false);
|
453
470
|
|
454
471
|
return this;
|
455
472
|
}
|
package/src/utility/array.js
CHANGED
@@ -66,7 +66,7 @@ export class Arr
|
|
66
66
|
|
67
67
|
if ( Any.isFunction(key) ) {
|
68
68
|
keys = keys.sort((a, b) => {
|
69
|
-
return
|
69
|
+
return key.call({}, obj[a], obj[b]);
|
70
70
|
});
|
71
71
|
}
|
72
72
|
|
@@ -90,16 +90,6 @@ export class Arr
|
|
90
90
|
{
|
91
91
|
let keys = Any.keys(obj);
|
92
92
|
|
93
|
-
if ( Any.isFunction(key) ) {
|
94
|
-
keys = keys.sort((a, b) => {
|
95
|
-
|
96
|
-
let va = Any.string(Obj.get(obj[a], key)).toLowerCase();
|
97
|
-
let vb = Any.string(Obj.get(obj[b], key)).toLowerCase();
|
98
|
-
|
99
|
-
return(va < vb) ? -1 : (va > vb) ? 1 : 0;
|
100
|
-
});
|
101
|
-
}
|
102
|
-
|
103
93
|
if ( ! Any.isFunction(key) ) {
|
104
94
|
keys = keys.sort((a, b) => {
|
105
95
|
|
package/src/utility/dom.js
CHANGED
package/src/utility/number.js
CHANGED
@@ -1,16 +1,16 @@
|
|
1
|
-
import { Any, Arr } from "../index"
|
1
|
+
import { Any, Arr, Obj } from "../index"
|
2
2
|
|
3
3
|
export class Num
|
4
4
|
{
|
5
5
|
static int(num)
|
6
6
|
{
|
7
|
-
return !
|
7
|
+
return !Any.isString(num) ? parseInt(num) :
|
8
8
|
parseInt(num.replace('px', ''));
|
9
9
|
}
|
10
10
|
|
11
11
|
static float(num)
|
12
12
|
{
|
13
|
-
return !
|
13
|
+
return !Any.isString(num) ? parseFloat(num) :
|
14
14
|
parseFloat(num.replace('px', ''));
|
15
15
|
}
|
16
16
|
|
@@ -43,9 +43,10 @@ export class Num
|
|
43
43
|
{
|
44
44
|
let value = 0;
|
45
45
|
|
46
|
-
for ( let i = 20; i >= 0; i-- ) {
|
46
|
+
for ( let i = 20; i >= 0; i -- ) {
|
47
47
|
if ( num >= (value = Math.pow(2, i)) ) {
|
48
|
-
base.push(value);
|
48
|
+
base.push(value);
|
49
|
+
num -= value;
|
49
50
|
}
|
50
51
|
}
|
51
52
|
|
@@ -57,11 +58,42 @@ export class Num
|
|
57
58
|
return Arr.reduce(arr, (acc, val) => acc + val, 0);
|
58
59
|
}
|
59
60
|
|
61
|
+
static distance(cord1, cord2, miles = false)
|
62
|
+
{
|
63
|
+
let defaultCord = {
|
64
|
+
lat: 0, lng: 0
|
65
|
+
};
|
66
|
+
|
67
|
+
cord1 = Obj.assign({}, defaultCord, cord1);
|
68
|
+
cord2 = Obj.assign({}, defaultCord, cord2);
|
69
|
+
|
70
|
+
let radlat1 = (Math.PI * this.float(cord1.lat)) / 180;
|
71
|
+
let radlat2 = (Math.PI * this.float(cord2.lat)) / 180;
|
72
|
+
|
73
|
+
let theta = this.float(cord1.lng) - this.float(cord2.lng);
|
74
|
+
let radtheta = (Math.PI * theta) / 180;
|
75
|
+
|
76
|
+
let dist = Math.sin(radlat1) * Math.sin(radlat2) +
|
77
|
+
Math.cos(radlat1) * Math.cos(radlat2) * Math.cos(radtheta);
|
78
|
+
|
79
|
+
if ( dist > 1 ) {
|
80
|
+
dist = 1;
|
81
|
+
}
|
82
|
+
|
83
|
+
dist = (Math.acos(dist) * 180) / Math.PI * 60 * 1.1515;
|
84
|
+
|
85
|
+
if ( !miles ) {
|
86
|
+
dist = dist * 1.609344;
|
87
|
+
}
|
88
|
+
|
89
|
+
return dist;
|
90
|
+
}
|
91
|
+
|
60
92
|
static format(num, decimal = '.', thousand = ',', fixed = null)
|
61
93
|
{
|
62
94
|
let value = num.toString();
|
63
95
|
|
64
|
-
if ( fixed !== null && fixed !== -1 ) {
|
96
|
+
if ( fixed !== null && fixed !== - 1 ) {
|
65
97
|
value = num.toFixed(fixed);
|
66
98
|
}
|
67
99
|
|
@@ -80,7 +112,7 @@ export class Num
|
|
80
112
|
|
81
113
|
let result = splits.reverse().join(thousand);
|
82
114
|
|
83
|
-
if ( fixed !== -1 && fixed !== 0 && value.match(/\./) ) {
|
115
|
+
if ( fixed !== - 1 && fixed !== 0 && value.match(/\./) ) {
|
84
116
|
result += decimal + minals;
|
85
117
|
}
|
86
118
|
|
package/src/utility/object.js
CHANGED
@@ -144,7 +144,7 @@ export class Obj
|
|
144
144
|
|
145
145
|
if ( Any.isFunction(key) ) {
|
146
146
|
keys = keys.sort((a, b) => {
|
147
|
-
return
|
147
|
+
return key.call({}, obj[a], obj[b]);
|
148
148
|
});
|
149
149
|
}
|
150
150
|
|
@@ -168,16 +168,6 @@ export class Obj
|
|
168
168
|
{
|
169
169
|
let keys = Any.keys(obj);
|
170
170
|
|
171
|
-
if ( Any.isFunction(key) ) {
|
172
|
-
keys = keys.sort((a, b) => {
|
173
|
-
|
174
|
-
let va = Any.string(Obj.get(obj[a], key)).toLowerCase();
|
175
|
-
let vb = Any.string(Obj.get(obj[b], key)).toLowerCase();
|
176
|
-
|
177
|
-
return(va < vb) ? -1 : (va > vb) ? 1 : 0;
|
178
|
-
});
|
179
|
-
}
|
180
|
-
|
181
171
|
if ( ! Any.isFunction(key) ) {
|
182
172
|
keys = keys.sort((a, b) => {
|
183
173
|
|