/**
VectorMap和ImageMap是通过AGSMapView实例出来的对象
**/
self.VectorMap = [[AGSMapView alloc]initWithFrame:CGRectMake(0, 0, viewWidth/2, viewHeight)];
self.VectorMap.tag = 0;
self.VectorMap.layerDelegate = self;
self.VectorMap.touchDelegate = self;
[self addSubview:self.VectorMap];
self.VectorMap.layer.borderColor = [UIColor zjcChangeFloat:@"#555555"].CGColor;
self.VectorMap.layer.borderWidth = 0.8;
self.ImageMap = [[AGSMapView alloc]initWithFrame:CGRectMake(viewWidth/2, 0, viewWidth/2, viewHeight)];
self.ImageMap.tag = 1;
self.ImageMap.layerDelegate = self;
self.ImageMap.touchDelegate = self;
[self addSubview:self.ImageMap];
self.ImageMap.layer.borderColor = [UIColor zjcChangeFloat:@"#555555"].CGColor;
self.ImageMap.layer.borderWidth = 0.8;
//这是影像 和 矢量
// TianMapLayer *TianDiTuLyrimage = [[TianMapLayer alloc]initWithType:TianMapTypeImage2000 localServiceURL:nil];
// TianMapLayer *TianDiTuLyr_Annoimage = [[TianMapLayer alloc]initWithType:TianMapTypeImageAnnotationChinese2000 localServiceURL:nil];
// TianDiTuLyrimage.visible = NO;
// TianDiTuLyr_Annoimage.visible = NO;
// TianMapLayer *TianDiTuLyrSL = [[TianMapLayer alloc]initWithType:TianMapTypeImage2000 localServiceURL:nil];
// TianMapLayer *TianDiTuLyr_SL = [[TianMapLayer alloc]initWithType:TianMapTypeImageAnnotationChinese2000 localServiceURL:nil];
// TianDiTuLyrSL = NO;
// TianDiTuLyr_SL.visible = NO;
//分别加入到mapView容器中,下面代码只显示加入影响的,矢量的我没写(方法和影响一样)
[self.ImageMap mapLayerForName:@"tiandituimage"].visible = YES;
[self.ImageMap mapLayerForName:@"image2000"].visible = YES;
- (void)respondToEnvChanged: (NSNotification*) notification {
AGSSpatialReference *sccc = [AGSSpatialReference spatialReferenceWithWKID:4490];
AGSEnvelope *extent = [AGSEnvelope envelopeWithXmin:MM ymin:YY xmax:ZZ ymax:DD spatialReference:sccc];
[self.VectorMap zoomToEnvelope:extent animated:YES];
[self.VectorMap zoomToEnvelope:extent animated:YES];
}
- (void)respondToEnvChange: (NSNotification*) notification {
AGSMapView *mapView = (AGSMapView *)notification.object;
NSInteger mapName = mapView.tag;
CGRect rect = mapView.bounds;
AGSEnvelope *env = [mapView toMapEnvelope:rect];
if (mapName == 0) {
[self.ImageMap zoomToEnvelope:env animated:YES];
}
else
{
[self.VectorMap zoomToEnvelope:env animated:YES];
[self.MapView zoomToEnvelope:env animated:YES];
}
}
//主控制器里面添加通知。
[[NSNotificationCenter defaultCenter] addObserver:self.doubleScreenView selector:@selector(respondToEnvChange:) name:AGSMapViewDidEndPanningNotification object:nil];
// register for zoom notifications AGSMapViewDidLoadNotification
[[NSNotificationCenter defaultCenter] addObserver:self.doubleScreenView selector:@selector(respondToEnvChange:) name:AGSMapViewDidEndZoomingNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(respondToEnvChanged:) name:AGSMapViewDidLoadNotification object:nil];
AGSEnvelope *envelope = [[AGSEnvelope alloc]initWithSpatialReference:self.spatialReference];
[self.doubleScreenView.VectorMap zoomToEnvelope:envelope animated:YES];
[self.doubleScreenView.ImageMap zoomToEnvelope:envelope animated:YES];