iam using 5 layers .first i load my first layer and i set some zoom level.so for this how i know how much zoom scale iam using for my irst layer.i want to use this same zoom scale for remaining layers also.so how to find the zoom scale of Map.
How to find the zoom scale of map
Hi Raja,
As far as i understood, i guess your code maybe looks like below:
ShapeFileFeatureLayer layer = new ShapeFileFeatureLayer();
var zoomLevelSet = new ZoomLevelSet();
zoomLevelSet.CustomZoomLevels.Add(new ZoomLevel(scale1));
zoomLevelSet.CustomZoomLevels.Add(new ZoomLevel(scale2));
…
zoomLevelSet.CustomZoomLevels.Add(new ZoomLevel(scaleN));
layer.ZoomLevelSet = zoomLevelSet;
If i’m correct, I think you can loop the CusomZoomLevels to get all these scale, if something wrong with me, can you give more detail or some code?
Thanks,
Johnny
Hi Raja,
As far as i understood, i guess your code maybe looks like below:
ShapeFileFeatureLayer layer = new ShapeFileFeatureLayer();
var zoomLevelSet = new ZoomLevelSet();
zoomLevelSet.CustomZoomLevels.Add(new ZoomLevel(scale1));
zoomLevelSet.CustomZoomLevels.Add(new ZoomLevel(scale2));
…
zoomLevelSet.CustomZoomLevels.Add(new ZoomLevel(scaleN));
layer.ZoomLevelSet = zoomLevelSet;
If i’m correct, I think you can loop the CusomZoomLevels to get all these scale, if something wrong with me, can you give more detail or some code?
Thanks,
Johnny
actually when i load my layer i fix my map zoom size as Map1.ZoomToScale(100000);then i i click on zoom in on map.so my map zoom level is changed now i want to know that exact zoom scale of the map at present like (ex:20000 or 30000).how to find this zoom level.
You can find the current ZoomLevel by using something like the following. Here we are checking the ZoomLevel.Scale after every ExtentChanged event.
winformsMap1.CurrentExtentChanged += new EventHandler<CurrentExtentChangedWinformsMapEventArgs>(winformsMap1_CurrentExtentChanged);
void winformsMap1_CurrentExtentChanged(object sender, CurrentExtentChangedWinformsMapEventArgs e)
{
ZoomLevel zoomLevel = new ZoomLevelSet().GetZoomLevel(e.CurrentExtent, e.MapWidth, e.MapUnit);
Double scale = zoomLevel.Scale;
}
helo Ryan
In web edition we dont have CurrentExtentChanged this event.so which event i need to use here.
Hello rajanikanth,
Sorry for our mistake, you can add the below code in client side to suspend zoomed event:
<script type="text/javascript">
var OnMapCreated = function (map) {
map.events.register("zoomend", map, function (map) {
var currentExtent = map.object.getExtent();
var currentSize = map.object.getSize();
var mapUnit = map.object.getUnits();
CallServer(String.format("{0}:{1}:{2}:{3}:{4}:{5}",
currentExtent.left,
currentExtent.top,
currentExtent.right,
currentExtent.bottom,
currentSize.w,
mapUnit));
})
}
function CallServer(parameter)
{
<%= ClientScript.GetCallbackEventReference(this,"parameter","ReceiveServer",null) %>;
}
function ReceiveServer(parameter)
{
}
</script>
Then inherit the interface of “System.Web.UI.IcallbackEventHandler” and complete the two functions in server side as below:
public string GetCallbackResult()
{
return "";
}
public void RaiseCallbackEvent(string arg)
{
string[] args = arg.Split(':');
double leftBoundary = double.Parse(args[0]);
double topBoundary = double.Parse(args[1]);
double rightBoundary = double.Parse(args[2]);
double bottomBoundary = double.Parse(args[3]);
double mapWidth = double.Parse(args[4]);
string mapUnitsStr = args[5];
RectangleShape extent = new RectangleShape(leftBoundary, topBoundary, rightBoundary, bottomBoundary);
GeographyUnit mapUnits = GeographyUnit.Unknown;
if (mapUnitsStr == "degrees")
{
mapUnits = GeographyUnit.DecimalDegree;
}
ZoomLevel zoomLevel = new ZoomLevelSet().GetZoomLevel(extent, mapWidth, mapUnits);
double scale = zoomLevel.Scale;
}
When zoomed on client side, it will call server to handle its request, then you can get the specified scale in server call back event.
Regards,
Gary