@mint-ui/map 0.3.0-beta → 0.3.1-beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,139 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var MintMap = require('../../MintMap.js');
6
+
7
+ var getClusterInfo = function (basePixelSize, mapBounds, mapWidth, mapHeight, itemList, sizeFunction) {
8
+ var _a;
9
+
10
+ var rowCount = Number((mapWidth / basePixelSize).toFixed(0)) || 1;
11
+ var colCount = Number((mapHeight / basePixelSize).toFixed(0)) || 1;
12
+ var boundsLineSizeX = Number(((mapBounds.ne.lng - mapBounds.nw.lng) / rowCount).toFixed(7));
13
+ var boundsLineSizeY = Number(((mapBounds.nw.lat - mapBounds.se.lat) / colCount).toFixed(7));
14
+ var boundsList = [];
15
+ var boundsPos = [];
16
+ var tempX1, tempY1, tempX2, tempY2;
17
+
18
+ for (var i = 0; i < rowCount; i++) {
19
+ tempX1 = mapBounds.nw.lng + boundsLineSizeX * i;
20
+ tempX2 = mapBounds.nw.lng + boundsLineSizeX * (i + 1);
21
+ var rows = [];
22
+ boundsPos.push(rows);
23
+
24
+ for (var k = 0; k < colCount; k++) {
25
+ tempY2 = mapBounds.se.lat + boundsLineSizeY * k;
26
+ tempY1 = mapBounds.se.lat + boundsLineSizeY * (k + 1);
27
+ var thisBounds = MintMap.Bounds.fromNWSE(new MintMap.Position(tempY1, tempX1), new MintMap.Position(tempY2, tempX2));
28
+ var includedList = thisBounds.getIncludedPositions(itemList);
29
+ rows.push({
30
+ bounds: thisBounds,
31
+ checked: false,
32
+ center: false,
33
+ centerPosition: thisBounds.getCenter(),
34
+ incList: [],
35
+ itemList: includedList,
36
+ size: basePixelSize
37
+ });
38
+ boundsList.push(thisBounds);
39
+ }
40
+ }
41
+
42
+ var centerList = [];
43
+ var totalItemCount = 0;
44
+ var min;
45
+ var max;
46
+
47
+ for (var i = 0; i < boundsPos.length; i++) {
48
+ for (var k = 0; k < boundsPos[i].length; k++) {
49
+ var curr = boundsPos[i][k];
50
+ if (curr.checked) continue;
51
+ curr.checked = true;
52
+ var incList = [];
53
+
54
+ if (boundsPos[i]) {
55
+ boundsPos[i][k - 1] && incList.push(boundsPos[i][k - 1]);
56
+ boundsPos[i][k + 1] && incList.push(boundsPos[i][k + 1]);
57
+ }
58
+
59
+ if (boundsPos[i - 1]) {
60
+ boundsPos[i - 1][k - 1] && incList.push(boundsPos[i - 1][k - 1]);
61
+ boundsPos[i - 1][k] && incList.push(boundsPos[i - 1][k]);
62
+ boundsPos[i - 1][k + 1] && incList.push(boundsPos[i - 1][k + 1]);
63
+ }
64
+
65
+ if (boundsPos[i + 1]) {
66
+ boundsPos[i + 1][k + 1] && incList.push(boundsPos[i + 1][k + 1]);
67
+ boundsPos[i + 1][k] && incList.push(boundsPos[i + 1][k]);
68
+ boundsPos[i + 1][k - 1] && incList.push(boundsPos[i + 1][k - 1]);
69
+ }
70
+
71
+ for (var _i = 0, incList_1 = incList; _i < incList_1.length; _i++) {
72
+ var inc = incList_1[_i];
73
+ if (inc.checked) continue;
74
+ inc.checked = true;
75
+
76
+ if (inc.itemList && inc.itemList.length > 0) {
77
+ curr.incList.push(inc);
78
+
79
+ (_a = curr.itemList).push.apply(_a, inc.itemList);
80
+
81
+ curr.center = true;
82
+ }
83
+ }
84
+
85
+ if (curr.center) {
86
+ centerList.push(curr);
87
+ var avrLat = calculateAverage(curr.itemList.map(function (item) {
88
+ return item.lat;
89
+ }));
90
+ var avrLng = calculateAverage(curr.itemList.map(function (item) {
91
+ return item.lng;
92
+ }));
93
+ curr.centerPosition = new MintMap.Position(avrLat, avrLng);
94
+ totalItemCount += curr.itemList.length;
95
+
96
+ if (!min || curr.itemList.length < min) {
97
+ min = curr.itemList.length;
98
+ }
99
+
100
+ if (!max || curr.itemList.length > max) {
101
+ max = curr.itemList.length;
102
+ }
103
+ }
104
+ }
105
+ }
106
+
107
+ var status = {
108
+ total: totalItemCount,
109
+ average: totalItemCount / centerList.length,
110
+ min: min,
111
+ max: max
112
+ };
113
+
114
+ sizeFunction = sizeFunction || function (info, status) {
115
+ var minSize = basePixelSize / 4;
116
+ var maxSize = basePixelSize;
117
+ return Math.min(Math.max(basePixelSize * info.itemList.length / status.average, minSize), maxSize);
118
+ };
119
+
120
+ for (var _b = 0, centerList_1 = centerList; _b < centerList_1.length; _b++) {
121
+ var center = centerList_1[_b];
122
+ center.size = sizeFunction(center, status);
123
+ }
124
+
125
+ return [centerList, boundsList];
126
+ };
127
+
128
+ var calculateAverage = function (nums) {
129
+ var sum = 0;
130
+
131
+ for (var _i = 0, nums_1 = nums; _i < nums_1.length; _i++) {
132
+ var num = nums_1[_i];
133
+ sum += num;
134
+ }
135
+
136
+ return Number((sum / nums.length).toFixed(7));
137
+ };
138
+
139
+ exports.getClusterInfo = getClusterInfo;
@@ -1,3 +1,4 @@
1
1
  export * from './animation';
2
2
  export * from './calculate';
3
3
  export * from './waiting';
4
+ export * from './cluster';
package/dist/index.es.js CHANGED
@@ -2167,6 +2167,138 @@ function MapBuildingProjection(props) {
2167
2167
  }, "".concat(title, " (").concat(numberOfFloor, "\uCE35)")))));
2168
2168
  }
2169
2169
 
2170
+ var getClusterInfo = function (basePixelSize, mapBounds, mapWidth, mapHeight, itemList, sizeFunction) {
2171
+ var _a;
2172
+
2173
+ var rowCount = Number((mapWidth / basePixelSize).toFixed(0)) || 1;
2174
+ var colCount = Number((mapHeight / basePixelSize).toFixed(0)) || 1;
2175
+ var boundsLineSizeX = Number(((mapBounds.ne.lng - mapBounds.nw.lng) / rowCount).toFixed(7));
2176
+ var boundsLineSizeY = Number(((mapBounds.nw.lat - mapBounds.se.lat) / colCount).toFixed(7));
2177
+ var boundsList = [];
2178
+ var boundsPos = [];
2179
+ var tempX1, tempY1, tempX2, tempY2;
2180
+
2181
+ for (var i = 0; i < rowCount; i++) {
2182
+ tempX1 = mapBounds.nw.lng + boundsLineSizeX * i;
2183
+ tempX2 = mapBounds.nw.lng + boundsLineSizeX * (i + 1);
2184
+ var rows = [];
2185
+ boundsPos.push(rows);
2186
+
2187
+ for (var k = 0; k < colCount; k++) {
2188
+ tempY2 = mapBounds.se.lat + boundsLineSizeY * k;
2189
+ tempY1 = mapBounds.se.lat + boundsLineSizeY * (k + 1);
2190
+ var thisBounds = Bounds.fromNWSE(new Position(tempY1, tempX1), new Position(tempY2, tempX2));
2191
+ var includedList = thisBounds.getIncludedPositions(itemList);
2192
+ rows.push({
2193
+ bounds: thisBounds,
2194
+ checked: false,
2195
+ center: false,
2196
+ centerPosition: thisBounds.getCenter(),
2197
+ incList: [],
2198
+ itemList: includedList,
2199
+ size: basePixelSize
2200
+ });
2201
+ boundsList.push(thisBounds);
2202
+ }
2203
+ }
2204
+
2205
+ var centerList = [];
2206
+ var totalItemCount = 0;
2207
+ var min;
2208
+ var max;
2209
+
2210
+ for (var i = 0; i < boundsPos.length; i++) {
2211
+ for (var k = 0; k < boundsPos[i].length; k++) {
2212
+ var curr = boundsPos[i][k];
2213
+ if (curr.checked) continue;
2214
+ curr.checked = true;
2215
+ var incList = [];
2216
+
2217
+ if (boundsPos[i]) {
2218
+ boundsPos[i][k - 1] && incList.push(boundsPos[i][k - 1]);
2219
+ boundsPos[i][k + 1] && incList.push(boundsPos[i][k + 1]);
2220
+ }
2221
+
2222
+ if (boundsPos[i - 1]) {
2223
+ boundsPos[i - 1][k - 1] && incList.push(boundsPos[i - 1][k - 1]);
2224
+ boundsPos[i - 1][k] && incList.push(boundsPos[i - 1][k]);
2225
+ boundsPos[i - 1][k + 1] && incList.push(boundsPos[i - 1][k + 1]);
2226
+ }
2227
+
2228
+ if (boundsPos[i + 1]) {
2229
+ boundsPos[i + 1][k + 1] && incList.push(boundsPos[i + 1][k + 1]);
2230
+ boundsPos[i + 1][k] && incList.push(boundsPos[i + 1][k]);
2231
+ boundsPos[i + 1][k - 1] && incList.push(boundsPos[i + 1][k - 1]);
2232
+ }
2233
+
2234
+ for (var _i = 0, incList_1 = incList; _i < incList_1.length; _i++) {
2235
+ var inc = incList_1[_i];
2236
+ if (inc.checked) continue;
2237
+ inc.checked = true;
2238
+
2239
+ if (inc.itemList && inc.itemList.length > 0) {
2240
+ curr.incList.push(inc);
2241
+
2242
+ (_a = curr.itemList).push.apply(_a, inc.itemList);
2243
+
2244
+ curr.center = true;
2245
+ }
2246
+ }
2247
+
2248
+ if (curr.center) {
2249
+ centerList.push(curr);
2250
+ var avrLat = calculateAverage(curr.itemList.map(function (item) {
2251
+ return item.lat;
2252
+ }));
2253
+ var avrLng = calculateAverage(curr.itemList.map(function (item) {
2254
+ return item.lng;
2255
+ }));
2256
+ curr.centerPosition = new Position(avrLat, avrLng);
2257
+ totalItemCount += curr.itemList.length;
2258
+
2259
+ if (!min || curr.itemList.length < min) {
2260
+ min = curr.itemList.length;
2261
+ }
2262
+
2263
+ if (!max || curr.itemList.length > max) {
2264
+ max = curr.itemList.length;
2265
+ }
2266
+ }
2267
+ }
2268
+ }
2269
+
2270
+ var status = {
2271
+ total: totalItemCount,
2272
+ average: totalItemCount / centerList.length,
2273
+ min: min,
2274
+ max: max
2275
+ };
2276
+
2277
+ sizeFunction = sizeFunction || function (info, status) {
2278
+ var minSize = basePixelSize / 4;
2279
+ var maxSize = basePixelSize;
2280
+ return Math.min(Math.max(basePixelSize * info.itemList.length / status.average, minSize), maxSize);
2281
+ };
2282
+
2283
+ for (var _b = 0, centerList_1 = centerList; _b < centerList_1.length; _b++) {
2284
+ var center = centerList_1[_b];
2285
+ center.size = sizeFunction(center, status);
2286
+ }
2287
+
2288
+ return [centerList, boundsList];
2289
+ };
2290
+
2291
+ var calculateAverage = function (nums) {
2292
+ var sum = 0;
2293
+
2294
+ for (var _i = 0, nums_1 = nums; _i < nums_1.length; _i++) {
2295
+ var num = nums_1[_i];
2296
+ sum += num;
2297
+ }
2298
+
2299
+ return Number((sum / nums.length).toFixed(7));
2300
+ };
2301
+
2170
2302
  var css_248z = ".MintMapWrapper-module_mint-map-control-wrapper__DDb4y {\n position: absolute;\n z-index: 101;\n}\n\n.MintMapWrapper-module_mint-map-overlay-wrapper__Jn4wV {\n position: absolute;\n z-index: 1;\n}";
2171
2303
  var styles = {"mint-map-control-wrapper":"MintMapWrapper-module_mint-map-control-wrapper__DDb4y","mint-map-overlay-wrapper":"MintMapWrapper-module_mint-map-overlay-wrapper__Jn4wV"};
2172
2304
  styleInject(css_248z);
@@ -2263,4 +2395,4 @@ function MapPolylineWrapper(_a) {
2263
2395
  return React.createElement(React.Fragment, null, options && children);
2264
2396
  }
2265
2397
 
2266
- export { AnimationPlayer, Bounds, Drawable, GeoCalulator, GoogleMintMapController, MapBuildingProjection, MapControlWrapper, MapMarkerWrapper, MapPolygonWrapper, MapPolylineWrapper, Marker, MintMap, MintMapController, MintMapCore, MintMapProvider, NaverMintMapController, Offset, Polygon, PolygonCalculator, Polyline, Position, useMarkerMoving, useMintMapController, waiting };
2398
+ export { AnimationPlayer, Bounds, Drawable, GeoCalulator, GoogleMintMapController, MapBuildingProjection, MapControlWrapper, MapMarkerWrapper, MapPolygonWrapper, MapPolylineWrapper, Marker, MintMap, MintMapController, MintMapCore, MintMapProvider, NaverMintMapController, Offset, Polygon, PolygonCalculator, Polyline, Position, getClusterInfo, useMarkerMoving, useMintMapController, waiting };
package/dist/index.js CHANGED
@@ -11,6 +11,7 @@ var MintMapProvider = require('./components/mint-map/core/provider/MintMapProvid
11
11
  var animation = require('./components/mint-map/core/util/animation.js');
12
12
  var calculate = require('./components/mint-map/core/util/calculate.js');
13
13
  var waiting = require('./components/mint-map/core/util/waiting.js');
14
+ var cluster = require('./components/mint-map/core/util/cluster.js');
14
15
  var MapControlWrapper = require('./components/mint-map/core/wrapper/MapControlWrapper.js');
15
16
  var MapMarkerWrapper = require('./components/mint-map/core/wrapper/MapMarkerWrapper.js');
16
17
  var MapPolygonWrapper = require('./components/mint-map/core/wrapper/MapPolygonWrapper.js');
@@ -38,6 +39,7 @@ exports.AnimationPlayer = animation.AnimationPlayer;
38
39
  exports.GeoCalulator = calculate.GeoCalulator;
39
40
  exports.PolygonCalculator = calculate.PolygonCalculator;
40
41
  exports.waiting = waiting.waiting;
42
+ exports.getClusterInfo = cluster.getClusterInfo;
41
43
  exports.MapControlWrapper = MapControlWrapper.MapControlWrapper;
42
44
  exports.MapMarkerWrapper = MapMarkerWrapper.MapMarkerWrapper;
43
45
  exports.MapPolygonWrapper = MapPolygonWrapper.MapPolygonWrapper;
package/dist/index.umd.js CHANGED
@@ -2172,6 +2172,138 @@
2172
2172
  }, "".concat(title, " (").concat(numberOfFloor, "\uCE35)")))));
2173
2173
  }
2174
2174
 
2175
+ var getClusterInfo = function (basePixelSize, mapBounds, mapWidth, mapHeight, itemList, sizeFunction) {
2176
+ var _a;
2177
+
2178
+ var rowCount = Number((mapWidth / basePixelSize).toFixed(0)) || 1;
2179
+ var colCount = Number((mapHeight / basePixelSize).toFixed(0)) || 1;
2180
+ var boundsLineSizeX = Number(((mapBounds.ne.lng - mapBounds.nw.lng) / rowCount).toFixed(7));
2181
+ var boundsLineSizeY = Number(((mapBounds.nw.lat - mapBounds.se.lat) / colCount).toFixed(7));
2182
+ var boundsList = [];
2183
+ var boundsPos = [];
2184
+ var tempX1, tempY1, tempX2, tempY2;
2185
+
2186
+ for (var i = 0; i < rowCount; i++) {
2187
+ tempX1 = mapBounds.nw.lng + boundsLineSizeX * i;
2188
+ tempX2 = mapBounds.nw.lng + boundsLineSizeX * (i + 1);
2189
+ var rows = [];
2190
+ boundsPos.push(rows);
2191
+
2192
+ for (var k = 0; k < colCount; k++) {
2193
+ tempY2 = mapBounds.se.lat + boundsLineSizeY * k;
2194
+ tempY1 = mapBounds.se.lat + boundsLineSizeY * (k + 1);
2195
+ var thisBounds = Bounds.fromNWSE(new Position(tempY1, tempX1), new Position(tempY2, tempX2));
2196
+ var includedList = thisBounds.getIncludedPositions(itemList);
2197
+ rows.push({
2198
+ bounds: thisBounds,
2199
+ checked: false,
2200
+ center: false,
2201
+ centerPosition: thisBounds.getCenter(),
2202
+ incList: [],
2203
+ itemList: includedList,
2204
+ size: basePixelSize
2205
+ });
2206
+ boundsList.push(thisBounds);
2207
+ }
2208
+ }
2209
+
2210
+ var centerList = [];
2211
+ var totalItemCount = 0;
2212
+ var min;
2213
+ var max;
2214
+
2215
+ for (var i = 0; i < boundsPos.length; i++) {
2216
+ for (var k = 0; k < boundsPos[i].length; k++) {
2217
+ var curr = boundsPos[i][k];
2218
+ if (curr.checked) continue;
2219
+ curr.checked = true;
2220
+ var incList = [];
2221
+
2222
+ if (boundsPos[i]) {
2223
+ boundsPos[i][k - 1] && incList.push(boundsPos[i][k - 1]);
2224
+ boundsPos[i][k + 1] && incList.push(boundsPos[i][k + 1]);
2225
+ }
2226
+
2227
+ if (boundsPos[i - 1]) {
2228
+ boundsPos[i - 1][k - 1] && incList.push(boundsPos[i - 1][k - 1]);
2229
+ boundsPos[i - 1][k] && incList.push(boundsPos[i - 1][k]);
2230
+ boundsPos[i - 1][k + 1] && incList.push(boundsPos[i - 1][k + 1]);
2231
+ }
2232
+
2233
+ if (boundsPos[i + 1]) {
2234
+ boundsPos[i + 1][k + 1] && incList.push(boundsPos[i + 1][k + 1]);
2235
+ boundsPos[i + 1][k] && incList.push(boundsPos[i + 1][k]);
2236
+ boundsPos[i + 1][k - 1] && incList.push(boundsPos[i + 1][k - 1]);
2237
+ }
2238
+
2239
+ for (var _i = 0, incList_1 = incList; _i < incList_1.length; _i++) {
2240
+ var inc = incList_1[_i];
2241
+ if (inc.checked) continue;
2242
+ inc.checked = true;
2243
+
2244
+ if (inc.itemList && inc.itemList.length > 0) {
2245
+ curr.incList.push(inc);
2246
+
2247
+ (_a = curr.itemList).push.apply(_a, inc.itemList);
2248
+
2249
+ curr.center = true;
2250
+ }
2251
+ }
2252
+
2253
+ if (curr.center) {
2254
+ centerList.push(curr);
2255
+ var avrLat = calculateAverage(curr.itemList.map(function (item) {
2256
+ return item.lat;
2257
+ }));
2258
+ var avrLng = calculateAverage(curr.itemList.map(function (item) {
2259
+ return item.lng;
2260
+ }));
2261
+ curr.centerPosition = new Position(avrLat, avrLng);
2262
+ totalItemCount += curr.itemList.length;
2263
+
2264
+ if (!min || curr.itemList.length < min) {
2265
+ min = curr.itemList.length;
2266
+ }
2267
+
2268
+ if (!max || curr.itemList.length > max) {
2269
+ max = curr.itemList.length;
2270
+ }
2271
+ }
2272
+ }
2273
+ }
2274
+
2275
+ var status = {
2276
+ total: totalItemCount,
2277
+ average: totalItemCount / centerList.length,
2278
+ min: min,
2279
+ max: max
2280
+ };
2281
+
2282
+ sizeFunction = sizeFunction || function (info, status) {
2283
+ var minSize = basePixelSize / 4;
2284
+ var maxSize = basePixelSize;
2285
+ return Math.min(Math.max(basePixelSize * info.itemList.length / status.average, minSize), maxSize);
2286
+ };
2287
+
2288
+ for (var _b = 0, centerList_1 = centerList; _b < centerList_1.length; _b++) {
2289
+ var center = centerList_1[_b];
2290
+ center.size = sizeFunction(center, status);
2291
+ }
2292
+
2293
+ return [centerList, boundsList];
2294
+ };
2295
+
2296
+ var calculateAverage = function (nums) {
2297
+ var sum = 0;
2298
+
2299
+ for (var _i = 0, nums_1 = nums; _i < nums_1.length; _i++) {
2300
+ var num = nums_1[_i];
2301
+ sum += num;
2302
+ }
2303
+
2304
+ return Number((sum / nums.length).toFixed(7));
2305
+ };
2306
+
2175
2307
  var css_248z = ".MintMapWrapper-module_mint-map-control-wrapper__DDb4y {\n position: absolute;\n z-index: 101;\n}\n\n.MintMapWrapper-module_mint-map-overlay-wrapper__Jn4wV {\n position: absolute;\n z-index: 1;\n}";
2176
2308
  var styles = {"mint-map-control-wrapper":"MintMapWrapper-module_mint-map-control-wrapper__DDb4y","mint-map-overlay-wrapper":"MintMapWrapper-module_mint-map-overlay-wrapper__Jn4wV"};
2177
2309
  styleInject__default["default"](css_248z);
@@ -2289,6 +2421,7 @@
2289
2421
  exports.PolygonCalculator = PolygonCalculator;
2290
2422
  exports.Polyline = Polyline;
2291
2423
  exports.Position = Position;
2424
+ exports.getClusterInfo = getClusterInfo;
2292
2425
  exports.useMarkerMoving = useMarkerMoving;
2293
2426
  exports.useMintMapController = useMintMapController;
2294
2427
  exports.waiting = waiting;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mint-ui/map",
3
- "version": "0.3.0-beta",
3
+ "version": "0.3.1-beta",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.es.js",
6
6
  "browser": "./dist/index.umd.js",