|
POST
|
I have some code that adjusts the zoom level of the map based on a zoom factor. The problem is the map does not zoom in or out from the center but slightly offset from the center. The map content shifts toward the upper left each time a zoom out occurs. The map shifts toward the lower right when a zoom in occurs. The map has a UITextField (named scaleLabel) where it displays the current scale and the user can type in the desired scale in this textField (for example, the user might type in 600 to get 1"=600'). After dismissing the keyboard, the map adjusts to the new scale. Please note that this posting only shows the code that I believe to be relevant. If you need more, I'd be glad to add it. Header file:
#import <UIKit/UIKit.h>
#import "ArcGIS.h"
@interface MapView : UIViewController <UITextFieldDelegate,
AGSMapViewLayerDelegate, AGSMapViewTouchDelegate>
{
AGSMapView *_mapView;
UITextField *scaleLabel;
UIView *inputAccessoryView;
float scaleCurrentValue;
}
// class properties
@property (nonatomic, retain) IBOutlet AGSMapView *mapView;
@property (nonatomic, retain) IBOutlet UITextField *scaleLabel;
// could not use retain (since a float is not an object?)
@property (nonatomic, assign) float scaleCurrentValue;
// method prototypes
-(void)zoomToGraphicsLayer;
-(void)respondToEnvChange:(NSNotification *)notification;
-(NSDictionary *)findMapCenter;
-(void)zoomMapByChangingScaleText;
@end
Selected methods from the implementation file: In the code below, I setup the notifications to listen for changes in the zoom level or map's extent.
-(void)mapViewDidLoad:(AGSMapView *)mapView
{
// register for "MapDidEndPanning" notifications
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(respondToEnvChange:)
name:@"MapDidEndPanning" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(respondToEnvChange:)
name:@"MapDidEndZooming" object:nil];
// scaleLabel is a UITextField that shows and allows the user to change the map's scale.
scaleLabel.text = [NSString stringWithFormat:@"%.0f", (self.mapView.mapScale / 2.54) / 12];
}
Below is how we calculate the center of the map. We need centerX and centerY to be used in zoomWithFactor's atAnchorPoint argument. Notice that this method is called by zoomMapByChangingScaleText and this method returns an NSDictionary.
-(NSDictionary *)findMapCenter
{
NSDictionary *mapCenterMethod;
float mapCenterX = ( (self.mapView.envelope.xmax - self.mapView.envelope.xmin ) / 2 ) + self.mapView.envelope.xmin;
float mapCenterY = ((self.mapView.envelope.ymax - self.mapView.envelope.ymin) / 2) + self.mapView.envelope.ymin;
mapCenterMethod = [NSDictionary dictionaryWithObjectsAndKeys:
@"centerX", [NSNumber numberWithFloat:mapCenterX],
@"centerY", [NSNumber numberWithFloat:mapCenterY], nil];
NSLog(@"mapCenterMethod: %f; %f",mapCenterX, mapCenterY);
// put X and Y values into an NSDictionary
return mapCenterMethod;
}
Below is where the zoom operation takes place.
-(void)zoomMapByChangingScaleText
{
if ( self.scaleCurrentValue != [scaleLabel.text floatValue] )
{
// run the findMapCenter method.
// put the return value in an NSDictionary.
NSDictionary *mapCenter = [self findMapCenter];
// get the new value in the UITextField since the done button was tapped.
float newScaleValue = [scaleLabel.text floatValue];
// calculate the zoom factor.
float zoomFactor = newScaleValue / self.scaleCurrentValue;
[self.mapView zoomWithFactor:zoomFactor
atAnchorPoint:CGPointMake([[mapCenter objectForKey:@"centerX"] floatValue], [[mapCenter objectForKey:@"centerY"] floatValue])
animated:YES];
[scaleLabel resignFirstResponder];
}
else // scale did not change...hide the keyboard.
{
[scaleLabel resignFirstResponder];
}
}
Thank you for any help, Paul Lohr
... View more
09-26-2011
12:35 AM
|
0
|
3
|
3751
|
|
POST
|
Hello dhanu11, Which version of the SDK are you using? It will probably help if you can post some of your relevant code. I have found that AGSMapView's zoomWithFactor method will zoom to "white areas" if the atAnchorPoint argument is a pair of X/Y values that are far from the current map's extent. Perhaps this is your issue?
... View more
09-26-2011
12:25 AM
|
0
|
0
|
398
|
|
POST
|
Thanks for taking your time to work on this, Nimesh. Your solution is good...I can see the values for each variable using Step Over which was definitely a concern. This had me hung up for a while but now I'm glad there is a solution. On my part I should have done more experimenting with Xcode so that maybe I could have figured this out and would not have needed to bother you. But I sure appreciate the help. Thanks again, Paul Lohr
... View more
09-20-2011
03:16 PM
|
0
|
0
|
529
|
|
POST
|
I bet you are using a base layer for your AGSMapView that has a spatial reference of something other than 4326 (WGS 1984). If this is the case, try using a base layer that uses the 4326 spatial reference. Or you can use AGSGeometryEngine to convert your points to the coordinate system of your map. Hope this helps, Paul Lohr
... View more
09-20-2011
06:13 AM
|
0
|
0
|
404
|
|
POST
|
I would like to set a maximum zoom level for my map. Currently I am using AGSGraphicsLayer:zoomToEnvelope to automatically zoom to a set of AGSGraphics but it often zooms in too far (Map Data Not Yet Available). My base layer is an AGSTiledMapServiceLayer. I would think there would be a "maxZoomLevel" read/write property for AGSMapView but I'm not seeing it or anything similar. I found this thread that mentions AGSLOD but I don't really understand the code: http://forums.arcgis.com/threads/7150-How-to-map-zoom-in-level Thank you for any help, Paul Lohr
... View more
09-20-2011
04:12 AM
|
0
|
3
|
3153
|
|
POST
|
This makes sense, Nimesh. madgame, What is the URL of the REST endpoint for the first layer that is added to the map? I think this will help us determine if we are talking about a spatial reference issue.
... View more
09-19-2011
08:02 AM
|
0
|
0
|
558
|
|
POST
|
As always, you knew how to fix it. Thank you, Nimesh. One thing that seems odd - I had to change: "AGSPoint *myPointReprojected;" to "AGSGeometry *myPointReprojected;" Before I made this change, I got a warning messaging stating "Incompatible pointer types assigning AGSPoint from AGSGeometry". I see in the documentation that projectGeometry:toSpatialReference outputs an AGSGeometry object. I thought if I were to input an AGSPoint, the method would return an AGSPoint (AGSPoint inherits from AGSGeometry). Instead it returns an AGSGeometry object. No complaints here, just glad it works and appreciative of the help. Paul Lohr
... View more
09-15-2011
11:19 AM
|
0
|
0
|
1291
|
|
POST
|
I have not been able to find any samples that use AGSGeometryEngine projectGeometry: toSpatialReference:. Xcode is telling me that it cannot find a method named projectGeometry:toSpatialReference. The warning messages are: warning: Semantic Issue: Class method '+projectGeometry:toSpatialReference:'
not found (return type defaults to 'id')
'AGSGeometryEngine' may not respond to '+projectGeometry:toSpatialReference:'
Here is the code that generates the warning: (please note that myPoint is an AGSPoint...a type of AGSGeometry with it's spatial reference being 4326 (WGS1984)) AGSPoint *myPointReprojected;
myPointReprojected = [AGSGeometryEngine projectGeometry:myPoint
toSpatialReference:[AGSSpatialReference webMercatorSpatialReference]]; Thank you for even the smallest amount of help, Paul Lohr
... View more
09-15-2011
04:01 AM
|
0
|
9
|
3745
|
|
POST
|
Hello Nimesh, Thanks for stepping in to help me with this again. I have attached a few screen shots - a breakpoint and an error message. Keep in mind that this type of error will come up with a breakpoint set near any call to any AGS class. If you need anything else to make this easy, just let me know. Much appreciated. Paul Lohr
... View more
09-15-2011
12:27 AM
|
0
|
0
|
529
|
|
POST
|
Are you wanting to edit features that are stored locally on the iPhone or iPad?
... View more
09-14-2011
12:33 PM
|
0
|
0
|
411
|
|
POST
|
This is kind of old but what the heck. Is the spatial reference of the first layer added to the mapView the same as the feature layer you add afterwards? Or perhaps I am misunderstanding. Also, you mentioned that you remove the feature layer and then add it back in to get the features to display at the correct location. And, if you don't remove/add your features, they show up at 0,0. I did not see the remove/add operation in your code. You don't have to share this but I am interested since this is similar to a problem I am having with AGSGraphic. Paul Lohr
... View more
09-14-2011
03:42 AM
|
0
|
0
|
558
|
|
POST
|
Still working on this problem. I had an experienced programmer look at this and he was not sure what to do. Is there a way to tell Xcode not to try to step through these AGS implementation files? It seems like a strange request that might not make sense but I don't know what else to ask. Not being able to step through code makes the ArcGIS iOS sdk very difficult to work with.
... View more
09-14-2011
03:19 AM
|
0
|
0
|
1281
|
|
POST
|
Thank you for helping, Nimesh. I suspect the problem is in my code. Now that I think about it, I have seen this before - where I have something wrong with my code but Xcode reports a missing implementation file of an underlying SDK instead of reporting the actual error. I found this information on stackoverflow but can't seem to find it again.
... View more
09-08-2011
06:14 AM
|
0
|
0
|
1281
|
|
POST
|
Many of us struggle with a lack of cellular reception at some point. I am pretty sure that caching part of a map could only be done by writing a custom ArcGIS application. You could hire a developer to do this. Sorry I don't have a better answer.
... View more
09-06-2011
04:40 AM
|
0
|
0
|
530
|
|
POST
|
I've found that setting a breakpoint then stepping through the code will sometimes show where the problem is occurring. You may need to move the breakpoint in a trial and error process to find the problem. Maybe you've tried this already? Sorry I don't have more help on this.
... View more
09-06-2011
04:36 AM
|
0
|
0
|
1078
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 06-20-2025 07:01 AM | |
| 1 | 07-18-2024 10:19 AM | |
| 1 | 09-13-2024 05:27 AM | |
| 1 | 09-12-2024 12:27 PM | |
| 1 | 07-10-2024 04:04 AM |
| Online Status |
Offline
|
| Date Last Visited |
06-27-2025
08:54 AM
|