How to disable FeatureLayer callout function

2978
2
Jump to solution
04-27-2015 04:54 AM
QKunZhu
New Contributor II

I am adding callout to my Map and it works fine.

I create a pushpin:

AGSPictureMarkerSymbol *pushpin = [AGSPictureMarkerSymbol pictureMarkerSymbolWithImageNamed:@"BluePushpin.png"];
pushpin.offset = CGPointMake(9, 16);
pushpin.leaderPoint = CGPointMake(-9, 11);

Then I add the callout pushpin to may callout layer

AGSPoint *theTask = [AGSPoint pointWithX:latitude y:longitude doubleValue]
                                spatialReference:self.mapView.spatialReference];
AGSGraphic graphic = [AGSGraphic graphicWithGeometry:theTask symbol:pushpin attributes:singleDataDic];
[self.taskInfoLayer addGraphic:graphic];

Everything works fine, when I tap on a pin point, it actually shows something.

The problem happened after I added some other layer:

NSURL *featureBldgURL = [NSURL URLWithString:LAYER_BLDG_URL];
AGSFeatureLayer *bldgLayer = [AGSFeatureLayer featureServiceLayerWithURL:featureBldgURL mode:AGSFeatureLayerModeOnDemand];
[self.mapView addMapLayer:bldgLayer withName:LAYER_BLDG_NAME];

Even when I tap on a place where I did not put a pushpin, it still shows up an empty callout dialog:

tmp.png

I found that the AGSFeatureLayer has implement AGSLayerCalloutDelegate, maybe it's the reason to show an empty callout when user tap on that AGSFeatureLayer?

How can I disable the callout for AGSFeatureLayer? Or, any other solution for this problem?

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
GagandeepSingh
Occasional Contributor II

Hi QKun Zhu​,

You can customize the behavior of the callout using the calloutDelegate (AGSLayerCalloutDelegate).

Assign the calloutDelegate on the blgLayer as the view controller. And in the same view controller implement the following delegate method. If you return NO or false, the callout won't be shown. So you can use this method to show the callout selectively.

(BOOL) - callout:willShowForFeature:layer:mapPoint:

"This method is called when a user taps on some features in a layer. Delegates should implement this method when they want to configure how a callout looks for a particular feature in a particular layer. Some properties delegates may want to configure are title, detail, image, customView, etc. The delegate should return YES for the callout to be shown. The delegate can return NO for those features for which a callout should not be shown. If this method is not implemented, AGSCallout::delegate will be consulted instead."

I hope this helps.

Gagan

View solution in original post

0 Kudos
2 Replies
GagandeepSingh
Occasional Contributor II

Hi QKun Zhu​,

You can customize the behavior of the callout using the calloutDelegate (AGSLayerCalloutDelegate).

Assign the calloutDelegate on the blgLayer as the view controller. And in the same view controller implement the following delegate method. If you return NO or false, the callout won't be shown. So you can use this method to show the callout selectively.

(BOOL) - callout:willShowForFeature:layer:mapPoint:

"This method is called when a user taps on some features in a layer. Delegates should implement this method when they want to configure how a callout looks for a particular feature in a particular layer. Some properties delegates may want to configure are title, detail, image, customView, etc. The delegate should return YES for the callout to be shown. The delegate can return NO for those features for which a callout should not be shown. If this method is not implemented, AGSCallout::delegate will be consulted instead."

I hope this helps.

Gagan

0 Kudos
QKunZhu
New Contributor II

Hi Gagandeep Singh,

Thank you so much.

My problem was I implement AGSCalloutDelegate, and this protocol and AGSLayerCalloutDelegate has the same method:

- (BOOL)callout:(AGSCallout *)callout willShowForFeature:(id<AGSFeature>)feature layer:(AGSLayer<AGSHitTestable> *)layer mapPoint:(AGSPoint *)mapPoint;

In my implementation, I made it aways return YES, which is the cause of my problem.

I fixed it by checking the layer type and return NO if user tap on other layer, and it works fine now.

0 Kudos