Map Resolutions

3309
12
08-15-2011 10:52 PM
Labels (1)
JamesMcElroy
New Contributor
I want to set the MaximumResolution property so that you can't zoom out past the full extent of the largest layer in a map pack.  Is there a way to programmatically get that value so that when you change map packs it can automatically calculate that?

Also, is there a way to force the map object to limit the pan range so you can't pan way over past the edge of the world and then zoom into whitespace and get lost?

Thanks,

James
0 Kudos
12 Replies
MichaelBranscomb
Esri Frequent Contributor
Hi,

I'll look into the MaximumResolution <> Map Package question.

Regarding limiting the pan - one very easy way to resolve this is setting the WrapAround property on the Map to True. Alternatively you could investigate listening for the map extent changed event then checking the requested extent against your restricted extent... but the overhead may be too great and/or getting the right user experience when they do try to navigate outside that extent may be tricky.

Cheers

Mike
0 Kudos
JamesMcElroy
New Contributor
The "WrapAround" property says that it only supports WGS84 projections.  The layers in my map package have GCS_WGS_1984 as the coordinate system.  I'm not sure if that's the same or not.  But when I set the property to true and add my LocalDynamicMapServiceLayer to the map control I checked the "WrapAroundIsActive" property and it was false, and the "SpatialProjection" of the map object was null.  Since it's a read-only property, how should I set the SpatialProject to the WGS84?

Thanks,

James
0 Kudos
MichaelBranscomb
Esri Frequent Contributor
Hi,

The WrapAround property supports both the following coordinate systems:

- WGS 1984 (WKID 4326) which is the same as your GCS_WGS_1984 map cordinate system
- WGS 1984 Web Mercator Auxilliarty Sphere (WKID 3857 / 102100)

The spatial reference property of the map control is determined by the coordinate system of the first valid layer added to the map. The map control does not support client-side projection-on-the-fly hence why the property is read-only.

If you're adding the layer in XAML... or even code... and hitting a break point to check the spatial reference of the map before the LocalMapService has initialized then the spatial reference might simply not have been set yet?

Cheers

Mike
0 Kudos
JamesMcElroy
New Contributor
Ok, well then it should work, but it doesn't.  I am loading the layer in code and adding to the map object after initializing it.  It's after that I set the property and check.  And after that when the map displays I can still pan off into the infinite display of white-space in any direction.

This is my code:
LocalArcGISDynamicMapServiceLayer lyr = new LocalArcGISDynamicMapServiceLayer(PATH_TO_MAP_PACK);
lyr.Initialize();
map.Layers.Add(lyr);
map.WrapAround = true;


After that line I check the properties on the map object and WrapAround is true but WrapAroundIsActive is false and the SpatialReference is null.
0 Kudos
MichaelBranscomb
Esri Frequent Contributor
Hi,

It's better to have the Map itself control the initialization of the layer rather than calling the Initialize() method directly. For example, try something along the following lines (assumes your Map's x:Name property is "MapControl"):


MapControl.WrapAround = true;

//Add a WGS84 tiled service:
ArcGISTiledMapServiceLayer arcGISTiledMapServiceLayer = new ArcGISTiledMapServiceLayer()
{
Url = "http://services.arcgisonline.com/ArcGIS/rest/services/ESRI_Imagery_World_2D/MapServer",
ID="WorldTopoMap"
};
MapControl.Layers.Add(arcGISTiledMapServiceLayer);

//Add a WGS84 Map Package asynchronously:
LocalMapService.GetServiceAsync(@"PATH_TO_MAP_PACK", (localMapService) =>
{
LocalArcGISDynamicMapServiceLayer localArcGISDynamicMapServiceLayer = new LocalArcGISDynamicMapServiceLayer()
{
Path = localMapService.Path,
ID = "TheLayerID",
ImageFormat = ArcGISDynamicMapServiceLayer.RestImageFormat.PNG32,
PanBuffer = PanBufferSize.Medium
};
MapControl.Layers.Add(localArcGISDynamicMapServiceLayer);
});

I'm interested to hear your results. If you're still not seeing the WrapAround property work as you expect - perhaps you could post a small, shareable, sample of your data that I can test?

Cheers

Mike
0 Kudos
MichaelBranscomb
Esri Frequent Contributor
Hi,

Following up on the question about limiting the pan extent and the maximum resolution <> map package question - you can use the ConstrainExtentBehaviour to achieve both goals:

http://resourcesbeta.arcgis.com/en/help/runtime-wpf/apiref/ESRI.ArcGIS.Client.Behaviors~ESRI.ArcGIS....

Which you can implement by doing the following:

1. Add the required references:

System.Windows.Interactivity.dll
ESRI.ArcGIS.Client.Behaviors.dll

2. Declare the System.Windows.Interactivity.dll namespace in your window delcaration:

xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"

3. Add a behaviour collection to the map and specify a ConstrainExtentBehavior in XAML:

<esri:Map x:Name="MyMap" Extent="-120,30,-60,60">
<i:Interaction.Behaviors>
<esriBehaviors:ConstrainExtentBehavior
ConstrainedExtent="-120,30,-60,60"/>                   
</i:Interaction.Behaviors>
</esri:Map>

4. Or do it in code:

XAML:

<i:Interaction.Behaviors>
<esriBehaviors:ConstrainExtentBehavior x:Name="Constraint" />
</i:Interaction.Behaviors>

Code:

using System.Windows.Interactivity;
using ESRI.ArcGIS.Client.Behaviors;

Envelope env = new ESRI.ArcGIS.Client.Geometry.Envelope(-13046639, 4036241, -13045773, 4036769);
Constraint.ConstrainedExtent = env;


Cheers

Mike
0 Kudos
JamesMcElroy
New Contributor
Hi,

It's better to have the Map itself control the initialization of the layer rather than calling the Initialize() method directly. For example, try something along the following lines (assumes your Map's x:Name property is "MapControl"):


MapControl.WrapAround = true;

//Add a WGS84 tiled service:
ArcGISTiledMapServiceLayer arcGISTiledMapServiceLayer = new ArcGISTiledMapServiceLayer()
{
Url = "http://services.arcgisonline.com/ArcGIS/rest/services/ESRI_Imagery_World_2D/MapServer",
ID="WorldTopoMap"
};
MapControl.Layers.Add(arcGISTiledMapServiceLayer);

//Add a WGS84 Map Package asynchronously:
LocalMapService.GetServiceAsync(@"PATH_TO_MAP_PACK", (localMapService) =>
{
LocalArcGISDynamicMapServiceLayer localArcGISDynamicMapServiceLayer = new LocalArcGISDynamicMapServiceLayer()
{
Path = localMapService.Path,
ID = "TheLayerID",
ImageFormat = ArcGISDynamicMapServiceLayer.RestImageFormat.PNG32,
PanBuffer = PanBufferSize.Medium
};
MapControl.Layers.Add(localArcGISDynamicMapServiceLayer);
});

I'm interested to hear your results. If you're still not seeing the WrapAround property work as you expect - perhaps you could post a small, shareable, sample of your data that I can test?

Cheers

Mike


I tried this way as well.  This time when I check properties after everything is loaded and running the "WrapAroundIsActive" is true, but it still allowed me to pan way off into the ocean of white-space and lose my way back to the map.  I have tried to attached the map pack I'm using, but it won't allow me to.  It lists the file size limit as 10MB for mpk files and mine is only 3.7MB, so I think the form is broken as I'm getting a "Request Entity Too Large" error.

I guess I'll try the Interactivity stuff next, but your response doesn't address how to find the max extent of the map pack dynamically, just how to set the values.

Thanks,

James
0 Kudos
JamesMcElroy
New Contributor
For adding the reference to the behaviors dll in the xaml, is there a schema for it or should I just add a direct assembly reference like so:

xmlns:esriBehaviors="clr-namespace:ESRI.ArcGIS.Client.Behaviors;assembly=ESRI.ArcGIS.Client.Behaviors"

Thanks,

James
0 Kudos
JamesMcElroy
New Contributor
I guess I'll try the Interactivity stuff next, but your response doesn't address how to find the max extent of the map pack dynamically, just how to set the values.


I figured it out.  I tied onto the map.Layers.LayersInitialized event and then grabbed the map.Extent which was automatically the entire map, and used that as the base for my constraint.  It works great.  Don't know why the WrapAround stuff doesn't work, but this Constraint might work out better anyways.

Thanks,

James
0 Kudos