How to show a callout, only on clicking on a markersymbol ?

1488
3
Jump to solution
02-19-2018 03:28 AM
PhaniBhushankolla
New Contributor

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.

0 Kudos
1 Solution

Accepted Solutions
MuruganandhamKuppan1
New Contributor III

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);

    

}

View solution in original post

3 Replies
MuruganandhamKuppan1
New Contributor III

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);

    

}

PhaniBhushankolla
New Contributor

Worked perfectly, thanks a lot.

0 Kudos
AsifIsmail
New Contributor III

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.

0 Kudos