2017-02-02 2 views
1

У меня есть один сценарий, как кластер для ближайшего CGPoint в UIView. Так я множество CGPoint NSArray, я пытаюсь получить ближайшее значение и не группироваться, но я не мог получить логику: // мой кодВ 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 
     } 
} 

Над кодом, время получить дубликаты точек, а также перекручивание переопределить на одном и том же объекте, так что, если кто-нибудь знает логический комментарий здесь, но я хочу, например, такие кластерные концепции, как кластер с географической картой с разбиением на страницы.

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) 
Смежные вопросы