开发者

Customized Annotation

开发者 https://www.devze.com 2023-02-12 02:27 出处:网络
i have a question regarding customized annotation here. Here is how i show the pin but i wish to insert an image in to the annotation when the user click on the pin. how can i do that?

i have a question regarding customized annotation here. Here is how i show the pin but i wish to insert an image in to the annotation when the user click on the pin. how can i do that?

- (void) showMarkingOnMap:(Service *) ser
    {
        if (!self.mapView.loaded) {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"iPoly" 
                                                            message:@"Failed to load the map."
                                                           delegate:self 
                                                  cancelButtonTitle:@"Ok" 
                                                  otherButtonTitles:nil, nil];
            [alert show];
            [alert release];

            return;

        }
        id<AGSLayerView> graphicsLayerView = [self.mapView.mapLayerViews objectForKey:@"GraphicsLayer"];
        AGSGraphicsLayer *graphicsLayer = (AGSGraphicsLayer*)graphicsLayerView.agsLayer;
        [graphicsLayer removeAllGraphics];

        // Create a symbols png graphic
        AGSP开发者_StackOverflowictureMarkerSymbol *genSymbol = [AGSPictureMarkerSymbol pictureMarkerSymbolWithImageNamed:@"pushpin.png"];
        ServiceInfoTemplate *infoTemplate = [[ServiceInfoTemplate alloc] init];
        AGSGraphic *genGraphic;
        AGSPoint *genPt;
        NSMutableDictionary *dic= [[NSMutableDictionary alloc] init];
        [dic setObject:[ser name] forKey:@"NAME"];
        if([ser.location isEqualToString: @"\n"] || (ser.location == nil)){
            [dic setObject:@"" forKey:@"DESC"];
        } else {
            [dic setObject:[ser location] forKey:@"DESC"];
        }
        genPt = [AGSPoint pointWithX:[[ser xcoordinate] floatValue]
                                        y:[[ser ycoordinate] floatValue]
                         spatialReference:self.mapView.spatialReference];
        genGraphic = [[AGSGraphic alloc] initWithGeometry:genPt symbol:genSymbol attributes:dic infoTemplateDelegate:infoTemplate];
        [graphicsLayer addGraphic:genGraphic];

        [graphicsLayer dataChanged];

        [self.mapView zoomWithFactor:0.1 atAnchorPoint:genPt.cgPoint animated:NO];
        [self.mapView centerAtPoint:genPt animated:YES];

        //CGPoint *pt = CGPointMake([[ser ycoordinate] floatValue], [[ser xcoordinate] floatValue]);


    }


It's not as easy as you might hope/think. Here's a full tutorial on how to do it. Note that with this implementation, your callout will occupy the entire width of the view.

See: http://blog.asolutions.com/2010/09/building-custom-map-annotation-callouts-part-1/

0

精彩评论

暂无评论...
验证码 换一张
取 消