Dear All,
I am using ThinkGeo version 7.0.0.0. I have loaded an jpeg image as Map using an GDI Raster Layer. To Restrict the Image to only small area within the original image i performed the following
a) Added RestrictionLayer with the zone as the required Restricted position.
b) tried with updating the RestrictedExtent as the required Restricted position.
c) MapUnit as Meter
If i use option 1, the Image is getting restricted to the required position but user is able to zoom out and see the original image.
if i use option 2, the image is getting restricted but user not able to do zoom/panning.
in both the cases if i use Meter as MapUnit then restriction not happening, but if i select MapUnit as DecimalDegree then restriction atleast happens.
So My requirement is Image should be restricted to the given rectangle shape ,but at the same time panning/zooming should not reveal the original image.
I have attached the original image and restricted image required. Please give in your suggestions for achieving the same.
Thanks
With Regards
Ravi
Restricting the Map Image to specific area
Hi Ravikumar,
Welcome to Map Suite Forums!
For your questions, I use the below codes and seems it works fine in my end:
private void WpfMap_Loaded(object sender, RoutedEventArgs e)
{
wpfMap1.MapUnit = GeographyUnit.Meter;
GdiPlusRasterLayer rasterLayer = new GdiPlusRasterLayer(@"…\imageData\Sapelo_2006_20080903T140150.jpg");
LayerOverlay overlay = new LayerOverlay();
overlay.Layers.Add(rasterLayer);
wpfMap1.Overlays.Add(overlay);
rasterLayer.Open();
wpfMap1.CurrentExtent = rasterLayer.GetBoundingBox();
RectangleShape restrictArea = rasterLayer.GetBoundingBox();
restrictArea.ScaleDown(50);
RestrictionLayer restrictionLayer = new RestrictionLayer();
restrictionLayer.Zones.Add(restrictArea);
restrictionLayer.RestrictionMode = RestrictionMode.ShowZones;
restrictionLayer.UpperScale = 250000000;
restrictionLayer.LowerScale = double.MinValue;
LayerOverlay restrictionOverlay = new LayerOverlay();
restrictionOverlay.Layers.Add(“RestrictionLayer”, restrictionLayer);
// option 2:
//wpfMap1.RestrictExtent = restrictArea;
//wpfMap1.MaximumScale = ExtentHelper.GetScale(wpfMap1.CurrentExtent, (float)wpfMap1.Width, GeographyUnit.Meter);
// option 1:
wpfMap1.Overlays.Add(“RestrictionOverlay”, restrictionOverlay);
wpfMap1.Refresh();
}
For the option1, user can’t see the whole image and only can see/pan in half of the image.
For the option2, we need to set the MaximumScale not only the RestrictExtent for the map.
I also attached the Test images so that you can test.
Hope it helps and if the issue persists, would you please send us a small sample or the images.
Regards,
Troy
imageData.zip (995 KB)
Thanks Troy,
I tried with the sample, but facing same issue with restricting the area. I am attaching my sample here. Please have a look at it.
In your sample, if we use the RestrictExtent, problem i am facing is zooming to the maximum scale happens with possibility to see the complete image.
thanks
with regards
ravi
TestThinkGeoMap.zip (1.85 MB)
Hi Ravikumar,
Thanks for the sample, I found some issues in the codes
1. comment out the restrictionLayer.Transparency = 1.0f;
2. the map layers initialization shouldn’t defined in the constructor of MainWindow, but in the Window_Loaded event. some codes like below:
public
MainWindow()
{
InitializeComponent();
wpfMap =
new
ThinkGeo.MapSuite.WpfDesktopEdition.WpfMap();
wpfMap.Background = Brushes.Black;
wpfMap.MapUnit = ThinkGeo.MapSuite.Core.GeographyUnit.Meter;
wpfMap.Visibility = System.Windows.Visibility.Visible;
wpfMap.Width = 800;
wpfMap.Height = 600;
this
.layoutGrid.Children.Add(wpfMap);
}
private
void
Window_Loaded_1(
object
sender, RoutedEventArgs routedEventArgs)
{
wpfMap.MapResizeMode = MapResizeMode.PreserveScaleAndCenter;
If the issue persists, please feel free to let us know.
Regards,
Troy
Hi Troy,
I tried with removing all the Layers Initialization from Constructor to Loaded event. Still could not get the expected results.
In the GeographicUnit of Meter, the RasterLayer does not make any changes to the original image. Rather if i set the GeographicUnit to DecimalDegree then only the expected results come. Does the Meter Unit not work well with Images(jpeg).?
Thanks
with regards
ravi
Hi Ravi,
I have test the meter, but seems it also works fine in my end, please try the attached file.
Also, here are some key codes:
PointShape upperleft = rasterLayer.GetBoundingBox().UpperLeftPoint;
PointShape lowerRight = upperleft.CloneDeep()
as
PointShape;
lowerRight.TranslateByOffset(100, -100);
RectangleShape restrictArea =
new
RectangleShape(upperleft, lowerRight);
RestrictionLayer restrictionLayer =
new
RestrictionLayer();
//maximumExtent.ScaleDown(50);
//restrictionLayer.Transparency = 1.0f;
restrictionLayer.Zones.Add(restrictArea);
restrictionLayer.RestrictionMode = RestrictionMode.ShowZones;
…
wpfMap.Overlays.Add(layerOverLay);
wpfMap.Overlays.Add(
“RestrictionOverlay”
, restrictionOverlay);
If the issue persists, please feel free to let us know.
Thanks,
Troy
001_MainWindow.xaml.cs.zip (3.15 KB)
Thanks Troy,
It works fine now. But i think the issue was with the order of adding the Overlays. In my source code I had the RestrictionOverlay added before the LayerOverlay. Is there any specific order to be followed while adding overlays?.
Thanks
with regards
ravi
Hi Ravikumar,
Glad to hear it helps.
Yes, there is a rule to add overlays into the map. In general, the first layeroverlay is inserted into map, then it will in the bottom of the map, the last inserted one will show on the top of the map. For the Restriction Overlay with a visible area, as we want it to overlap the whole layeroverlays, so we should add it as the last one.
Thanks,
Troy