Change mapView Layers using segmented control from another view controller

706
4
Jump to solution
12-12-2012 12:33 AM
AshishArora
New Contributor III
I have 2 UIViewControllers

1). sgViewController which contains mapView
2). ConfigViewController which contains one Segmented control with three buttons.

first view controller (sgViewController) has a button with segue (Partial curl) which shows second view controller.

In the second view controller, i have segmented control "mapTypeChanged". Based on selected segment index, i want to change the map view layers in first view controller (sgViewController).

here is what i am doing but unable to see what i am trying to achieve.

- (IBAction)mapTypeChanged:(id)sender {
   
   sgViewController *sVC = [self.storyboard instantiateViewControllerWithIdentifier:@"sgViewController"];
   
    switch (self.mapType.selectedSegmentIndex) {
        case 0:
            // aready here - do nothing
            break;
        case 1:
          
            [sVC.mapView reset];
            [sVC.mapView addMapLayer:LayerName withName:@"LayerName"];
           
            break;
        case 2:
            // will change more layers here

            break;
        default:
            break;
    }
   
}
0 Kudos
1 Solution

Accepted Solutions
AshishArora
New Contributor III
Hi,

I'm doing exact the same thing in my project and it works for me.
Have you tried to first remove the previous maplayer?

[mapView removeMapLayerWithName:@"blub"];


The second thing is this line:

sgViewController *sVC = [self.storyboard instantiateViewControllerWithIdentifier:@"sgViewController"];

I think this gives you a new instance of the sgViewController and not the one which is already initialized. I'm fairly new to objective-c so that could me wrong.
But if thats the problem:
Give the ConfigViewController a public sgViewController property and assign your sgViewController to it when you call the ConfigViewController.
Something like:
ConfigViewController* configViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"configView"]; [configViewController setSgViewController:self]; [self.navigationController pushViewController:configViewController animated:YES];





I am able to solve this issue by using Custom delegate which is being called on segmented control value change and points to map view controller with map type information. Based on the information received by map view controller, rest of the processing like add or remove layers take place.

View solution in original post

0 Kudos
4 Replies
PhilippFauser
New Contributor
Hi,

I'm doing exact the same thing in my project and it works for me.
Have you tried to first remove the previous maplayer?

[mapView removeMapLayerWithName:@"blub"];


The second thing is this line:

sgViewController *sVC = [self.storyboard instantiateViewControllerWithIdentifier:@"sgViewController"];

I think this gives you a new instance of the sgViewController and not the one which is already initialized. I'm fairly new to objective-c so that could me wrong.
But if thats the problem:
Give the ConfigViewController a public sgViewController property and assign your sgViewController to it when you call the ConfigViewController.
Something like:
ConfigViewController* configViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"configView"];
[configViewController setSgViewController:self];
[self.navigationController pushViewController:configViewController animated:YES];
0 Kudos
AshishArora
New Contributor III
Hi,

I'm doing exact the same thing in my project and it works for me.
Have you tried to first remove the previous maplayer?

[mapView removeMapLayerWithName:@"blub"];


The second thing is this line:

sgViewController *sVC = [self.storyboard instantiateViewControllerWithIdentifier:@"sgViewController"];

I think this gives you a new instance of the sgViewController and not the one which is already initialized. I'm fairly new to objective-c so that could me wrong.
But if thats the problem:
Give the ConfigViewController a public sgViewController property and assign your sgViewController to it when you call the ConfigViewController.
Something like:
ConfigViewController* configViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"configView"]; [configViewController setSgViewController:self]; [self.navigationController pushViewController:configViewController animated:YES];





I am able to solve this issue by using Custom delegate which is being called on segmented control value change and points to map view controller with map type information. Based on the information received by map view controller, rest of the processing like add or remove layers take place.
0 Kudos
PhilippFauser
New Contributor
Have you ever tried this with an AGSOpenStreetMapLayer?
I'm trying to change between an AGSDynamicMapServiceLayer and the AGSOpenStreetMapLayer but thats not working.

The changing between two different AGSDynamicMapServiceLayers is no problem, but as soon as I'm trying to add a AGSOpenStreetMapLayer after viewDidLoad happens nothing.
0 Kudos
AshishArora
New Contributor III
Have you ever tried this with an AGSOpenStreetMapLayer?
I'm trying to change between an AGSDynamicMapServiceLayer and the AGSOpenStreetMapLayer but thats not working.

The changing between two different AGSDynamicMapServiceLayers is no problem, but as soon as I'm trying to add a AGSOpenStreetMapLayer after viewDidLoad happens nothing.



As i said in my previous post that i am using custom delegate which is being called on segmented control value change.

in order to show open street map, first i reset the map before adding open street map layer and i am able to see the results.

[self.mapView reset];
[self.mapView addMapLayer:_openLayer withName:@"OpenStreetMap"];
0 Kudos