@mint-ui/map
Version:
- React map library - Control various map with one interface - Google, Naver, Kakao map supported now - Typescript supported - Canvas marker supported
143 lines (111 loc) • 4.57 kB
JavaScript
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var MapTypes = require('../../types/MapTypes.js');
var getClusterInfo = function (basePixelSize, mapBounds, mapWidth, mapHeight, itemList, sizeFunction) {
var _a; //1. basePixelSize 기준으로 현재 지도 크기를 베이스로 영역 갯수 정하기
var rowCount = Number((mapWidth / basePixelSize).toFixed(0)) || 1;
var colCount = Number((mapHeight / basePixelSize).toFixed(0)) || 1; //console.log('rowCount', rowCount, 'colCount', colCount)
var boundsLineSizeX = Number(((mapBounds.ne.lng - mapBounds.nw.lng) / rowCount).toFixed(7));
var boundsLineSizeY = Number(((mapBounds.nw.lat - mapBounds.se.lat) / colCount).toFixed(7)); //console.log('boundsLineSize', boundsLineSizeX, boundsLineSizeY)
var boundsPos = [];
var tempX1, tempY1, tempX2, tempY2;
for (var i = 0; i < rowCount; i++) {
tempX1 = mapBounds.nw.lng + boundsLineSizeX * i;
tempX2 = mapBounds.nw.lng + boundsLineSizeX * (i + 1);
var rows = [];
boundsPos.push(rows);
for (var k = 0; k < colCount; k++) {
tempY2 = mapBounds.se.lat + boundsLineSizeY * k;
tempY1 = mapBounds.se.lat + boundsLineSizeY * (k + 1);
var thisBounds = MapTypes.Bounds.fromNWSE(new MapTypes.Position(tempY1, tempX1), new MapTypes.Position(tempY2, tempX2));
var includedList = thisBounds.getIncludedPositions(itemList);
rows.push({
bounds: thisBounds,
checked: false,
center: false,
centerPosition: thisBounds.getCenter(),
incList: [],
itemList: includedList,
size: basePixelSize
});
}
} //좌표마다 검사해서 인접셀 병합 처리
var centerList = [];
var totalItemCount = 0;
var min;
var max;
for (var i = 0; i < boundsPos.length; i++) {
for (var k = 0; k < boundsPos[i].length; k++) {
var curr = boundsPos[i][k];
if (curr.checked) continue;
curr.checked = true; //현재기준 8방향 객체 모으기
var incList = [];
if (boundsPos[i]) {
boundsPos[i][k - 1] && incList.push(boundsPos[i][k - 1]);
boundsPos[i][k + 1] && incList.push(boundsPos[i][k + 1]);
}
if (boundsPos[i - 1]) {
boundsPos[i - 1][k - 1] && incList.push(boundsPos[i - 1][k - 1]);
boundsPos[i - 1][k] && incList.push(boundsPos[i - 1][k]);
boundsPos[i - 1][k + 1] && incList.push(boundsPos[i - 1][k + 1]);
}
if (boundsPos[i + 1]) {
boundsPos[i + 1][k + 1] && incList.push(boundsPos[i + 1][k + 1]);
boundsPos[i + 1][k] && incList.push(boundsPos[i + 1][k]);
boundsPos[i + 1][k - 1] && incList.push(boundsPos[i + 1][k - 1]);
}
for (var _i = 0, incList_1 = incList; _i < incList_1.length; _i++) {
var inc = incList_1[_i];
if (inc.checked) continue;
inc.checked = true;
if (inc.itemList && inc.itemList.length > 0) {
curr.incList.push(inc);
(_a = curr.itemList).push.apply(_a, inc.itemList);
curr.center = true;
}
}
if (curr.center) {
centerList.push(curr);
var avrLat = calculateAverage(curr.itemList.map(function (item) {
return item.lat;
}));
var avrLng = calculateAverage(curr.itemList.map(function (item) {
return item.lng;
}));
curr.centerPosition = new MapTypes.Position(avrLat, avrLng);
totalItemCount += curr.itemList.length;
if (!min || curr.itemList.length < min) {
min = curr.itemList.length;
}
if (!max || curr.itemList.length > max) {
max = curr.itemList.length;
}
}
}
}
var status = {
total: totalItemCount,
average: totalItemCount / centerList.length,
min: min,
max: max
};
sizeFunction = sizeFunction || function (info, status) {
var minSize = basePixelSize / 4;
var maxSize = basePixelSize;
return Math.min(Math.max(basePixelSize * info.itemList.length / status.average, minSize), maxSize);
};
for (var _b = 0, centerList_1 = centerList; _b < centerList_1.length; _b++) {
var center = centerList_1[_b];
center.size = sizeFunction(center, status);
} // console.log('centerList', centerList, status);
return centerList;
};
var calculateAverage = function (nums) {
var sum = 0;
for (var _i = 0, nums_1 = nums; _i < nums_1.length; _i++) {
var num = nums_1[_i];
sum += num;
}
return Number((sum / nums.length).toFixed(7));
};
exports.getClusterInfo = getClusterInfo;