Is there any delegate method to show a callout, by clicking on a marker symbol.
Similar to didTapAtScreenPoint delegate method, which displays a callout wherever the user clicks on the map.
Solved! Go to Solution.
There is no separate delegate. Here is some sample,
/* Create a graphics with symbol**/
AGSPoint * graphicPoint = [AGSPoint pointWithX:-9547261.91529309 y:4615891.15535562 spatialReference:[AGSSpatialReference webMercator]];
NSMutableDictionary * graphicAttributes = [NSMutableDictionary dictionaryWithObjectsAndKeys:
@"Frazier Museum", @"name",
@"829 West Main Street, Louisville, KY 40202", @"address",nil];
AGSPictureMarkerSymbol * graphicSymbol = [AGSPictureMarkerSymbol pictureMarkerSymbolWithImage:[UIImage imageNamed:@"Museum.png"]];
AGSGraphic * graphic = [AGSGraphic graphicWithGeometry:graphicPoint symbol:graphicSymbol attributes:graphicAttributes ];
/*** Add the graphics to AGSGraphicOverlay and add AGSGraphicOverlay as AGSMapview's subview ***/
[self.graphicsOverlay.graphics addObject:graphic];
/** use AGSGeoViewTouchDelegate to detect tap in mapview*/
- (void)geoView:(AGSGeoView *)geoView didTapAtScreenPoint:(CGPoint)screenPoint mapPoint:(AGSPoint *)mapPoint {
NSLog(@"didTapAtScreenPoint %@ %@",NSStringFromCGPoint(screenPoint), mapPoint);
__weak __typeof(self) weakSelf = self;
[self.mapView identifyGraphicsOverlay:self.graphicsOverlay screenPoint:screenPoint tolerance:12 returnPopupsOnly:NO maximumResults:1 completion:^(AGSIdentifyGraphicsOverlayResult * _Nonnull identifyResult) {
AGSGraphic *graphic = identifyResult.graphics.firstObject;
if (graphic){
// show callout for identified graphic
[weakSelf showCalloutForGraphic:graphic tapLocation:mapPoint];
}
else{
// nothing tapped - dismiss callout
[weakSelf.mapView.callout dismiss];
}
}];
}
-(void)showCalloutForGraphic: (AGSGraphic*)graphic tapLocation:(AGSPoint*)tapLocation {
self.mapView.callout.title = graphic.attributes[@"name"];
self.mapView.callout.detail = graphic.attributes[@"address"];
[self.mapView.callout setAccessoryButtonHidden :false];
[self.mapView.callout showCalloutForGraphic:graphic tapLocation:tapLocation animated:YES];
}
/** add below delegate methods to show the popups - AGSCalloutDelegate */
-(BOOL)callout:(AGSCallout*)callout willShowAtMapPoint:(AGSPoint *)mapPoint{
return TRUE;
}
-(BOOL)callout:(AGSCallout*)callout willShowForLocationDisplay:(AGSLocationDisplay*)locationDisplay {
return TRUE;
}
- (void)didTapAccessoryButtonForCallout:(AGSCallout *)callout {
if (![callout.representedObject isKindOfClass:[AGSGraphic class]]){
// we are expecting a graphic in this sample
return;
}
NSLog(@"%@",callout.title);
}
There is no separate delegate. Here is some sample,
/* Create a graphics with symbol**/
AGSPoint * graphicPoint = [AGSPoint pointWithX:-9547261.91529309 y:4615891.15535562 spatialReference:[AGSSpatialReference webMercator]];
NSMutableDictionary * graphicAttributes = [NSMutableDictionary dictionaryWithObjectsAndKeys:
@"Frazier Museum", @"name",
@"829 West Main Street, Louisville, KY 40202", @"address",nil];
AGSPictureMarkerSymbol * graphicSymbol = [AGSPictureMarkerSymbol pictureMarkerSymbolWithImage:[UIImage imageNamed:@"Museum.png"]];
AGSGraphic * graphic = [AGSGraphic graphicWithGeometry:graphicPoint symbol:graphicSymbol attributes:graphicAttributes ];
/*** Add the graphics to AGSGraphicOverlay and add AGSGraphicOverlay as AGSMapview's subview ***/
[self.graphicsOverlay.graphics addObject:graphic];
/** use AGSGeoViewTouchDelegate to detect tap in mapview*/
- (void)geoView:(AGSGeoView *)geoView didTapAtScreenPoint:(CGPoint)screenPoint mapPoint:(AGSPoint *)mapPoint {
NSLog(@"didTapAtScreenPoint %@ %@",NSStringFromCGPoint(screenPoint), mapPoint);
__weak __typeof(self) weakSelf = self;
[self.mapView identifyGraphicsOverlay:self.graphicsOverlay screenPoint:screenPoint tolerance:12 returnPopupsOnly:NO maximumResults:1 completion:^(AGSIdentifyGraphicsOverlayResult * _Nonnull identifyResult) {
AGSGraphic *graphic = identifyResult.graphics.firstObject;
if (graphic){
// show callout for identified graphic
[weakSelf showCalloutForGraphic:graphic tapLocation:mapPoint];
}
else{
// nothing tapped - dismiss callout
[weakSelf.mapView.callout dismiss];
}
}];
}
-(void)showCalloutForGraphic: (AGSGraphic*)graphic tapLocation:(AGSPoint*)tapLocation {
self.mapView.callout.title = graphic.attributes[@"name"];
self.mapView.callout.detail = graphic.attributes[@"address"];
[self.mapView.callout setAccessoryButtonHidden :false];
[self.mapView.callout showCalloutForGraphic:graphic tapLocation:tapLocation animated:YES];
}
/** add below delegate methods to show the popups - AGSCalloutDelegate */
-(BOOL)callout:(AGSCallout*)callout willShowAtMapPoint:(AGSPoint *)mapPoint{
return TRUE;
}
-(BOOL)callout:(AGSCallout*)callout willShowForLocationDisplay:(AGSLocationDisplay*)locationDisplay {
return TRUE;
}
- (void)didTapAccessoryButtonForCallout:(AGSCallout *)callout {
if (![callout.representedObject isKindOfClass:[AGSGraphic class]]){
// we are expecting a graphic in this sample
return;
}
NSLog(@"%@",callout.title);
}
Worked perfectly, thanks a lot.
Can u pls help me with swift.
I have set of marker from feature layer,tapping on it should bring up the call-out.
Please do help.