Reputation: 168
I have one scenario as do cluster for the nearest CGPoint in UIView. So i have set of CGPoint NSArray, I trying to get the nearest value and do cluster but i could not get the logic : // my code
//total CGpointArray ex: cgPointGroupArray, i try to get each obj closest obj
for (CGPoint firstObjOfCGPoint in cgPointGroupArray) {
for (CGPoint nextPoint in cgPointGroupArray) {
//ex: 30 -distance b/w two point
if (30>[self distanceBetween: firstObjOfCGPoint and:nextPoint]){
[shortestClusterArr addObject:nextPoint];
}
else{
[longestClusterArr addObject:nextPoint];
}
}
//if array hold more than 2 value it will cluster otherwise mark single obj
if(shortestClusterArr.count>2){
//clustered marker obj
[self addClusterMarker:shortestClusterArr];
}
else{
//no cluster marker obj
}
}
Above code, looping time getting duplicate points as well override on the same object so if anyone knows the logic comment here,.. But I want such as clustering concepts like Geo-map clustering with pagination.
Upvotes: 1
Views: 148
Reputation: 168
xTotalCount=pow( 2, self.mapScrollView.zoomLevel );
for ( int i = 0; i < xTotalCount ; i++) {
// ex : 0 < 2, it will execute 2 times depends on zoom level(pow(2,0),pow(2,1),pow(2,2),.. )
xISet = [[ NSMutableArray alloc ] init];
//set the cordination value to the a and b according to the zoom level
ax=( i*zoomLevelTicketSpacing ) / xTotalCount; // ex : a = 0
bx=((i + 1) *zoomLevelTicketSpacing ) / xTotalCount; // b = 256
for (EDCTicketMarker *ticketMarker in weakSelf.activeTicketMarkers) {
// group with zoom scale
nextPointX = ticketMarker.location.x;
if(nextPointX > ax && nextPointX < bx){
[xISet addObject:ticketMarker];
}
}
[xMatrixSet setValue:xISet forKey:[@(i)stringValue]];
// Y cordination ( 00, 01, 10, 11 )
yTotalCount=pow ( 2, self.mapScrollView.zoomLevel );
for (int j=0; j< yTotalCount ; j++) {
yISet = [[ NSMutableArray alloc ] init];
ay=( j*zoomLevelTicketSpacing ) / yTotalCount; // ex : a = 0
by=(( j+1 ) *zoomLevelTicketSpacing) / yTotalCount; // b = 256
for (EDCTicketMarker *ticketMarker in weakSelf.activeTicketMarkers) {
// group with zoom scale
nextPointY = ticketMarker.location.y;
if( nextPointY > ay && nextPointY < by ){
[yISet addObject:ticketMarker];
}
}
[yMatrixSet setValue:yISet forKey:[@(i)stringValue]];
// Intersect the X and Y matrix array
NSMutableSet *matrixSetX = [ NSMutableSet setWithArray:xISet ];
NSMutableSet *matrixSetY = [ NSMutableSet setWithArray:yISet ];
[matrixSetX intersectSet:matrixSetY];
NSArray *resultMatrix = [matrixSetX allObjects];
NSLog(resultMatrix) // it will print according to the x and y position (00,01,10,11)
Upvotes: 3