2017-02-02 4 views
1

UIViewで最も近いCGPointのクラスタを作成するシナリオが1つあります。同様に、重複のポイントを取得し、時間をループし、 //私のコードコードの上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) 
関連する問題