2017-02-02 1 views
1

UIView에서 가장 가까운 CGPoint에 대해 클러스터를 수행하는 시나리오가 하나 있습니다. 뿐만 아니라 중복 된 점을 얻는 시간을 반복, // 내 코드 코드 위Objective C에서 CATileLayer를 사용하여 페이지 매김을 사용하여 클러스터링하는 방법

//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 
     } 
} 

: 그래서 내가 가장 가까운 값을 얻기 위해 노력하고 클러스터 않습니다 CGPoint있는 NSArray의 설정하지만 난 논리를 가져올 수 없습니다 동일한 객체에 대한 재정의를 수행하면 누구나 논리 주석을 여기에서 알 수 있습니다. 그러나 저는 페이지 매김을 사용하는 지리 -지도 클러스터링과 같은 클러스터링 개념을 원합니다.

enter image description here

답변

3
  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) 
관련 문제