2011-10-11 102 views
0

我在新的應用程序中使用(非常酷)WhirlyGlobe(https://code.google.com/p/whirlyglobe/)iPhone全球3D顯示屏。我可以使用下面顯示的代碼在特定位置添加標籤。我希望能夠回去並刪除我之前添加的標籤。文檔(http://whirlyglobedocs.s3-website-us-east-1.amazonaws.com/html/interface_label_layer.html#ac17e1ec72e70eec416cb2cac833f46fa)顯示了一個removeLabel方法,但我似乎無法讓它工作。我可以添加但不刪除標籤。我嘗試循環遍歷所有子視圖,但找不到這些SimpleLabel實例。有人可以幫助我瞭解如何刪除標籤嗎?我沒有多少運氣找到很多例子。謝謝!使用WhirlyGlobe刪除標籤

// Current position 
float lat = [[values objectAtIndex:8] floatValue]; 
flaot lon = [[values objectAtIndex:9] floatValue]; 

// Create a SingleLabel at this Lat/Lon pair location     
SingleLabel *interimLabel = [[[SingleLabel alloc] init] autorelease]; 
interimLabel.text = [NSString stringWithFormat:@"PRN %d",[[values objectAtIndex:1] intValue]]; 
[interimLabel setLoc:GeoCoord::CoordFromDegrees(lon, lat)]; 
[locationArray addObject:interimLabel]; 
[allLabels addObject:interimLabel]; 
+0

當然在數組allLabels?或者locationArray? Google代碼頁上的Wiki上是否有類似的帖子? – Luke

+0

我可以看到代碼將標籤添加到圖層的位置嗎? – mousebird

+0

下面的答案就像一個魅力 - 謝謝。 – PhilBot

回答

0

當您向標籤圖層添加單個標籤或一組標籤時,您將獲得SimpleIdentity。保持在某個地方。然後,當您想要從標籤圖層中刪除標籤(或標籤組)時,您將返回該SimpleIdentity。

這是怎麼回事。 WhirlyGlobe批量繪製數據,如mofo。一旦Label Layer將它們壓縮成儘可能少的Drawables,它的SingleLabel對象就不再存在,並且它可以逃脫。因此,要引用這些標籤,您必須保留唯一的ID。

現在,如果您想分別刪除這些標籤或單獨更改其外觀,那麼您必須逐個添加它們。一個SimpleIdentity標籤。否則,無法單獨引用它們。

爲了提高速度,我建議將它們中的許多組合在一起,因爲您可以避開。如果現在太複雜了,請逐一添加它們,然後記下來回來。所以,當你說「爲什麼不按照我想要的那樣快速運行」時,你可以說「Ooooo,對吧。」

+0

有道理,像魅力一樣工作 - 謝謝。 – PhilBot