AGSPictureMarkerSymbol 标记

1
2
3
4
5
6
7
8
9
10
11
12
13
- (AGSGraphic *)pinAtPoint:(AGSPoint *)point info:(NSDictionary *)info
{
//要展示的图片
UIImage *image = __IMG(@"icon-forum");
AGSPictureMarkerSymbol *pictureMarkerSymbol = [AGSPictureMarkerSymbol pictureMarkerSymbolWithImage:image];
pictureMarkerSymbol.width =
pictureMarkerSymbol.height = 20;
//设置属性值 用于传参 在代理方法中可以获取到
AGSGraphic *graphic = [AGSGraphic graphicWithGeometry:point symbol:pictureMarkerSymbol attributes:info];
// Add polygon graphic to graphics overlay.
[self.graphicsOverlay.graphics addObject:graphic];
return graphic;
}

调用

1
2
3
4
for (YXForumDataInfoModel *m in ms) {
CLLocationCoordinate2D coords = CLLocationCoordinate2DMake(m.lat,m.lon);//纬度,经度
[[BDArcGISUtil ins] pinAtPoint:[AGSPoint pointWithCLLocationCoordinate2D:coords] info:[m yy_modelToJSONObject]];
}

AGSMapView的callout

为实现点击标点位置的点击,使用AGSMapView的如下回调

1
2
3
4
5
6
7
/** Tells the delegate that the user single-tapped at the specified location.
@param geoView on which the user performed the interaction.
@param screenPoint Location where the user tapped in screen coordinates.
@param mapPoint Location where the user tapped in map coordinates.
@since 100
*/
- (void)geoView:(AGSGeoView *)geoView didTapAtScreenPoint:(CGPoint)screenPoint mapPoint:(AGSPoint *)mapPoint;

为监测点击的区域是否打点区域,使用AGSMapView的如下方法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/** Identify (hit-test) which graphics appear at the specified screen coordinates in the provided graphics overlay.
@param graphicsOverlay in which to identify graphics
@param screenPoint at which to identify graphics
@param tolerance radius in points specifying how precise the identify operation should be. A value of 0 means that it should be extremely precise - only those graphics appearing at the exact coordinates should be returned. A value of 22 (a good default for touch displays which covers an average finger tap) means graphics appearing within a 44 pt buffer can also be returned. Max value permitted is 100.
@param returnPopupsOnly specifies what the identify results should contain. If set to YES, only overlays with popups will be retured. If set to NO, all overlays (with or without popups) will be retured.
@param maximumResults that should be returned as the result
@param completion block that is invoked when the operation is complete with the result.
@return operation which can be canceled
@since 100
*/
-(id<AGSCancelable>)identifyGraphicsOverlay:(AGSGraphicsOverlay*)graphicsOverlay
screenPoint:(CGPoint)screenPoint
tolerance:(double)tolerance
returnPopupsOnly:(BOOL)returnPopupsOnly
maximumResults:(NSInteger)maximumResults
completion:(void(^)(AGSIdentifyGraphicsOverlayResult *identifyResult))completion;

案例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#pragma mark Tap

- (void)geoView:(AGSGeoView *)geoView didTapAtScreenPoint:(CGPoint)screenPoint mapPoint:(AGSPoint *)mapPoint
{
[geoView identifyGraphicsOverlay:geoView.graphicsOverlays.firstObject screenPoint:screenPoint tolerance:12 returnPopupsOnly:NO maximumResults:1000 completion:^(AGSIdentifyGraphicsOverlayResult * _Nonnull identifyResult) {
if (identifyResult.error) {
NSLog(@"error %@",identifyResult.error.localizedDescription);
}else{
NSMutableArray *forumDataInfoModels = [NSMutableArray array];
//获得锚点的信息
for (AGSGraphic *graphic in identifyResult.graphics) {
NSLog(@"info %@",graphic.attributes);
YXForumDataInfoModel *m = [YXForumDataInfoModel yy_modelWithJSON:[graphic.attributes yy_modelToJSONObject]];
[forumDataInfoModels addObject:m];
}

// if info is exsit 弹出框
if (forumDataInfoModels.count) {
//callout
GPHomeMapCalloutView *customView = [UINib viewForNib:NSStringFromClass(GPHomeMapCalloutView.class)];
//set data
customView.forumDataInfoModels = forumDataInfoModels;
// add new
customView.didAddNew = ^(AGSPoint * _Nonnull point) {
addNewForum(point);
};
//did select item
customView.didSelectForum = ^(YXForumDataInfoModel * _Nonnull forumInfoModel) {
// dismiss callout
[geoView.callout dismiss];
// build a forum list model
YXFormListModel *flm = [YXFormListModel new];
flm.uuid = forumInfoModel.uuid;
//goto forum detail
[GPForumJumper jumpToForumWithType:[NSString stringWithFormat:@"%li",forumInfoModel.type] fromViewController:self taskModel:nil projectModel:nil point:mapPoint interfaceStatus:InterfaceStatus_Show forum:flm table:nil];
};
//add customer view
self.mapView.callout.customView = customView;
//show callout
[self.mapView.callout showCalloutAt:mapPoint screenOffset:CGPointZero rotateOffsetWithMap:YES animated:YES];
}
else{
[geoView.callout dismiss];
}
}
}];
}