I had a 2 point zoom function working with the last Beta version of Desktop Edition, but the changes to TrackOverlay have caused a problem. I was using TrackOverlay.TrackMode = TrackMode.Rectangle to prompt the usr to draw a box. Once drawn I would set the extent to the rectangle and call TrackOverlay.InternalFeatures.Clear(). The function is continuous, so I imediately go into TrackOverlay.TrackMode = TrackMode.Rectangle for another zoom window. With RC1, the TrackOverlay retains the first point of the rectangle, so if I set TrackOverlay.TrackMode = TrackMode.Rectangle a second time, the rectangle draws from the original first point to the current mouse location. How do I clear the TrackOverlay completely?
TrackMode Issue
Charles,
Just wonder which event are you using to set the current extent to the tracked rectangle, can you show us your code? Also could you let me know more about your scenario? Seems you are tring to implement the TrackZoomIn, can you use the TrackZoomIn directly?
Thanks,
Ben
This might be seperately related, but I have an Identify by point tool and it seems like my event does not fire off unless I double click. It worked fine in the previous version though.
TrackZoomIn is exactly what I am trying to do, but I can’t find any documentation of this method or procedure in the API documentation, nor is it used in the sample project. Is this part of MapSuite Desktop Edition 3.0? How does it work?
I think the problem might be that I am overriding the mouse up event in my own map control. I capture the track shape, set the map extent and clear the track overlay in my override. It occurs to me that the map control has not finished drawing the rectangle until it processes the mouse up event, which never happens.
Assuming the TrackZoomIn won’t work, is there a better way to capture the end of the draw rectangle process in the track overlay?
I have no problem giving you a copy of my code, but you would also need my sql server spatial database to make it work. It is about half a gig right now.
I am having a similar issue, but I can't get the extent to refresh. Here is the code. The base shape is valid and I am setting the trackmode as rectangle. I have also tried it with extentoverlay, but you have to have shift pressed. I tried setting the key to None and it still did not work.
void TrackOverlay_TrackEnded(object sender, TrackEndedTrackInteractiveOverlayEventArgs e)
{
BaseShape bs = e.TrackShape;
if (bs != null)
{
winformsMap1.CurrentExtent = bs.GetBoundingBox();
winformsMap1.Refresh();
}
}
I also can not get a track zoom in to work as described by Ed. I am using a nearly exact aproach. Sometimes I can see my new extents flash for a second then I am reverted back to the original.
Ed & Nelson,
Thanks for your sharing.
The case described in Ed code is a bug in latest version (3.0.307 RC1), we will fix it in next version.
Currently, we provide another solution to go around this problem; change the behavior of TrackZoomIn without key, attachment contains a demo. Also, you can take a look at another similar post as following link:
gis.thinkgeo.com/Support/DiscussionForums/tabid/143/aff/21/aft/5807/afv/topic/afpgj/1/Default.aspx#8734
Let me know if any further problems.
Thanks.
Yale
733-Post5807Demo.zip (11.8 KB)
The code in the zip file does what I originally described. Now I am trying to modify it somewhat.
The MouseDownCore override initiates the zoom window, the MouseMoveCore override draws the zoom window as the mouse moves, and the MouseUpCore override sets the extent and clears the zoom window. I want the MouseDownCore override to start and stop the zoom window drawing.
I have modified the code as follows:
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Windows.Forms;
using ThinkGeo.MapSuite.Core;
using ThinkGeo.MapSuite.DesktopEdition;
public enum MouseMode
{
Null = 0,
Pan = 1,
TrackZoomIn = 2,
WheelZoom = 3
}
public class CustomExtentInteractiveOverlay : ExtentInteractiveOverlay
{
private MouseMode mouseMode;
private PointShape startPoint;
private InMemoryFeatureLayer trackZoomInLayer;
private bool ResetNext = false;
private bool IsDrawing = false;
public CustomExtentInteractiveOverlay() : base()
{
mouseMode = MouseMode.Null;
startPoint = new PointShape();
trackZoomInLayer = new InMemoryFeatureLayer();
trackZoomInLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = new AreaStyle(new GeoPen(GeoColor.SimpleColors.Black, 2), new GeoSolidBrush(GeoColor.FromArgb(80, 239, 251, 239)));
trackZoomInLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
}
public void KeyUp(Keys KeyCode)
{
if (KeyCode.Equals(Keys.ShiftKey))
{
ResetNext = true;
}
}
public MouseMode MouseMode
{
get { return mouseMode; }
set { mouseMode = value; }
}
public override bool IsEmpty
{
get
{
return trackZoomInLayer.InternalFeatures.Count <= 0;
}
}
protected override InteractiveResult MouseDownCore(InteractionArguments interactionArguments)
{
InteractiveResult interactiveResult = base.MouseDownCore(interactionArguments);
if (IsDrawing)
{
if (PanAndTrackZoomState.OffsetXInScreen != 0 && PanAndTrackZoomState.OffsetYInScreen != 0)
{
PanAndTrackZoomState.EndXInScreen = interactionArguments.ScreenX;
PanAndTrackZoomState.EndYInScreen = interactionArguments.ScreenY;
PointShape upperLeft = ExtentHelper.ToWorldCoordinate(interactionArguments.CurrentExtent, PanAndTrackZoomState.UpperLeftPoint.X, PanAndTrackZoomState.UpperLeftPoint.Y, interactionArguments.MapWidth, interactionArguments.MapHeight);
PointShape lowerRight = ExtentHelper.ToWorldCoordinate(interactionArguments.CurrentExtent, PanAndTrackZoomState.LowRightPoint.X, PanAndTrackZoomState.LowRightPoint.Y, interactionArguments.MapWidth, interactionArguments.MapHeight);
if (mouseMode == MouseMode.TrackZoomIn && PanAndTrackZoomState.IsMouseLeftButtonDown)
{
RectangleShape tempExtent = new RectangleShape(upperLeft, lowerRight);
interactionArguments.CurrentExtent = tempExtent;
trackZoomInLayer.InternalFeatures.Clear();
if (ResetNext)
{
mouseMode = MouseMode.Null;
ResetNext = false;
}
interactiveResult.DrawThisOverlay = InteractiveOverlayDrawType.Draw;
interactiveResult.ProcessOtherOverlays = ProcessOtherOverlaysMode.DoNotProcessOtherOverlays;
}
}
PanAndTrackZoomState.IsLeftClickDragKeyPressed = false;
PanAndTrackZoomState.IsRightClickDragKeyPressed = false;
PanAndTrackZoomState.IsMouseLeftButtonDown = false;
PanAndTrackZoomState.IsMouseRightButtonDown = false;
IsDrawing = false;
}
else
{
startPoint.X = interactionArguments.WorldX;
startPoint.Y = interactionArguments.WorldY;
IsDrawing = true;
}
return interactiveResult;
}
protected override InteractiveResult MouseMoveCore(InteractionArguments interactionArguments)
{
InteractiveResult result = null;
if (IsDrawing)
{
result = new InteractiveResult();
PanAndTrackZoomState.EndXInScreen = interactionArguments.ScreenX;
PanAndTrackZoomState.EndYInScreen = interactionArguments.ScreenY;
if (mouseMode == MouseMode.TrackZoomIn)
{
trackZoomInLayer.InternalFeatures.Clear();
RectangleShape extend = GetExtentByTwoPointShapes(startPoint, new PointShape(interactionArguments.WorldX, interactionArguments.WorldY));
Lock.EnterWriteLock();
try
{
trackZoomInLayer.InternalFeatures.Add(new Feature(extend));
}
finally
{
Lock.ExitWriteLock();
}
result.DrawThisOverlay = InteractiveOverlayDrawType.Draw;
result.ProcessOtherOverlays = ProcessOtherOverlaysMode.DoNotProcessOtherOverlays;
}
else if (mouseMode == MouseMode.Pan && PanAndTrackZoomState.IsMouseLeftButtonDown)
{
RectangleShape newExtent = PanAndTrackZoomState.GetNewExtent(new ScreenPointF((float)interactionArguments.ScreenX, (float)interactionArguments.ScreenY), interactionArguments.CurrentExtent, interactionArguments.MapWidth, interactionArguments.MapHeight);
interactionArguments.CurrentExtent = newExtent;
result.DrawThisOverlay = InteractiveOverlayDrawType.Draw;
result.ProcessOtherOverlays = ProcessOtherOverlaysMode.DoNotProcessOtherOverlays;
}
}
else
{
result = base.MouseMoveCore(interactionArguments);
}
return result;
}
/*
protected override InteractiveResult MouseUpCore(InteractionArguments interactionArguments)
{
InteractiveResult result = new InteractiveResult();
if (PanAndTrackZoomState.OffsetXInScreen != 0 && PanAndTrackZoomState.OffsetYInScreen != 0)
{
PanAndTrackZoomState.EndXInScreen = interactionArguments.ScreenX;
PanAndTrackZoomState.EndYInScreen = interactionArguments.ScreenY;
PointShape upperLeft = ExtentHelper.ToWorldCoordinate(interactionArguments.CurrentExtent, PanAndTrackZoomState.UpperLeftPoint.X, PanAndTrackZoomState.UpperLeftPoint.Y, interactionArguments.MapWidth, interactionArguments.MapHeight);
PointShape lowerRight = ExtentHelper.ToWorldCoordinate(interactionArguments.CurrentExtent, PanAndTrackZoomState.LowRightPoint.X, PanAndTrackZoomState.LowRightPoint.Y, interactionArguments.MapWidth, interactionArguments.MapHeight);
if (mouseMode == MouseMode.TrackZoomIn && PanAndTrackZoomState.IsMouseLeftButtonDown)
{
RectangleShape tempExtent = new RectangleShape(upperLeft, lowerRight);
interactionArguments.CurrentExtent = tempExtent;
trackZoomInLayer.InternalFeatures.Clear();
if (ResetNext)
{
mouseMode = MouseMode.Null;
ResetNext = false;
}
result.DrawThisOverlay = InteractiveOverlayDrawType.Draw;
result.ProcessOtherOverlays = ProcessOtherOverlaysMode.DoNotProcessOtherOverlays;
}
}
PanAndTrackZoomState.IsLeftClickDragKeyPressed = false;
PanAndTrackZoomState.IsRightClickDragKeyPressed = false;
PanAndTrackZoomState.IsMouseLeftButtonDown = false;
PanAndTrackZoomState.IsMouseRightButtonDown = false;
return result;
}
*/
protected override void DrawCore(GeoCanvas canvas)
{
trackZoomInLayer.Open();
trackZoomInLayer.Draw(canvas, new Collection<SimpleCandidate>());
canvas.Flush();
trackZoomInLayer.Close();
}
private RectangleShape GetExtentByTwoPointShapes(PointShape startPointShape, PointShape endPointShape)
{
PointShape upperLeftPointShape = new PointShape(Math.Min(startPointShape.X, endPointShape.X), Math.Max(startPointShape.Y, endPointShape.Y));
PointShape lowerRightPointShape = new PointShape(Math.Max(startPointShape.X, endPointShape.X), Math.Min(startPointShape.Y, endPointShape.Y));
return new RectangleShape(upperLeftPointShape, lowerRightPointShape);
}
}
The problem is that the MouseDownCore doesn't fire while the zoom window is drawing. Why?
Charles
Charles,
Thanks for your reporting.
I changed some of your codes, and now it can start and stop the zoom window drawing in MapClick (instead of MouseDown).
But during this process, we found a potential bug in MapControl . We do not expect the extent will change in the MapClick or MouseDown, so we will not refresh the Map even though you change the extent.
So with this code, currently, you have to OnPaint( for example, minimize the window or hide it and show it) to see the result, we will fix this problem in next release.
If you are very urgent, we can send you a temporary version for this.
Thanks.
Yale
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Windows.Forms;
using ThinkGeo.MapSuite.Core;
using ThinkGeo.MapSuite.DesktopEdition;
public enum MouseMode
{
Null = 0,
Pan = 1,
TrackZoomIn = 2,
WheelZoom = 3
}
public class CustomExtentInteractiveOverlay : ExtentInteractiveOverlay
{
private MouseMode mouseMode;
private PointShape startPoint;
private InMemoryFeatureLayer trackZoomInLayer;
private bool ResetNext = false;
private bool IsDrawing = false;
public CustomExtentInteractiveOverlay()
: base()
{
mouseMode = MouseMode.Null;
startPoint = new PointShape();
trackZoomInLayer = new InMemoryFeatureLayer();
trackZoomInLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = new AreaStyle(new GeoPen(GeoColor.SimpleColors.Black, 2), new GeoSolidBrush(GeoColor.FromArgb(80, 239, 251, 239)));
trackZoomInLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
}
public void KeyUp(Keys KeyCode)
{
if (KeyCode.Equals(Keys.ShiftKey))
{
ResetNext = true;
}
}
public MouseMode MouseMode
{
get { return mouseMode; }
set { mouseMode = value; }
}
public override bool IsEmpty
{
get
{
return trackZoomInLayer.InternalFeatures.Count <= 0;
}
}
protected override InteractiveResult MouseClickCore(InteractionArguments interactionArguments)
{
PanAndTrackZoomState.IsMouseLeftButtonDown = true;
InteractiveResult interactiveResult = new InteractiveResult();
if (IsDrawing)
{
if (PanAndTrackZoomState.OffsetXInScreen != 0 && PanAndTrackZoomState.OffsetYInScreen != 0)
{
PanAndTrackZoomState.EndXInScreen = interactionArguments.ScreenX;
PanAndTrackZoomState.EndYInScreen = interactionArguments.ScreenY;
PointShape upperLeft = ExtentHelper.ToWorldCoordinate(interactionArguments.CurrentExtent, PanAndTrackZoomState.UpperLeftPoint.X, PanAndTrackZoomState.UpperLeftPoint.Y, interactionArguments.MapWidth, interactionArguments.MapHeight);
PointShape lowerRight = ExtentHelper.ToWorldCoordinate(interactionArguments.CurrentExtent, PanAndTrackZoomState.LowRightPoint.X, PanAndTrackZoomState.LowRightPoint.Y, interactionArguments.MapWidth, interactionArguments.MapHeight);
if (mouseMode == MouseMode.TrackZoomIn && PanAndTrackZoomState.IsMouseLeftButtonDown)
{
RectangleShape tempExtent = new RectangleShape(upperLeft, lowerRight);
interactionArguments.CurrentExtent = tempExtent;
trackZoomInLayer.InternalFeatures.Clear();
if (ResetNext)
{
mouseMode = MouseMode.Null;
ResetNext = false;
}
interactiveResult.DrawThisOverlay = InteractiveOverlayDrawType.Draw;
interactiveResult.ProcessOtherOverlays = ProcessOtherOverlaysMode.DoNotProcessOtherOverlays;
}
}
PanAndTrackZoomState.IsLeftClickDragKeyPressed = false;
PanAndTrackZoomState.IsRightClickDragKeyPressed = false;
PanAndTrackZoomState.IsMouseLeftButtonDown = false;
PanAndTrackZoomState.IsMouseRightButtonDown = false;
IsDrawing = false;
}
else
{
interactiveResult = base.MouseDownCore(interactionArguments);
startPoint.X = interactionArguments.WorldX;
startPoint.Y = interactionArguments.WorldY;
IsDrawing = true;
}
return interactiveResult;
}
//protected override InteractiveResult MouseDownCore(InteractionArguments interactionArguments)
//{
//}
protected override InteractiveResult MouseMoveCore(InteractionArguments interactionArguments)
{
InteractiveResult result = null;
if (IsDrawing)
{
result = new InteractiveResult();
PanAndTrackZoomState.EndXInScreen = interactionArguments.ScreenX;
PanAndTrackZoomState.EndYInScreen = interactionArguments.ScreenY;
if (mouseMode == MouseMode.TrackZoomIn)
{
trackZoomInLayer.InternalFeatures.Clear();
RectangleShape extend = GetExtentByTwoPointShapes(startPoint, new PointShape(interactionArguments.WorldX, interactionArguments.WorldY));
trackZoomInLayer.InternalFeatures.Add(new Feature(extend));
result.DrawThisOverlay = InteractiveOverlayDrawType.Draw;
result.ProcessOtherOverlays = ProcessOtherOverlaysMode.DoNotProcessOtherOverlays;
}
else if (mouseMode == MouseMode.Pan && PanAndTrackZoomState.IsMouseLeftButtonDown)
{
RectangleShape newExtent = PanAndTrackZoomState.GetNewExtent(new ScreenPointF((float)interactionArguments.ScreenX, (float)interactionArguments.ScreenY), interactionArguments.CurrentExtent, interactionArguments.MapWidth, interactionArguments.MapHeight);
interactionArguments.CurrentExtent = newExtent;
result.DrawThisOverlay = InteractiveOverlayDrawType.Draw;
result.ProcessOtherOverlays = ProcessOtherOverlaysMode.DoNotProcessOtherOverlays;
}
}
else
{
result = base.MouseMoveCore(interactionArguments);
}
return result;
}
/*
protected override InteractiveResult MouseUpCore(InteractionArguments interactionArguments)
{
InteractiveResult result = new InteractiveResult();
if (PanAndTrackZoomState.OffsetXInScreen != 0 && PanAndTrackZoomState.OffsetYInScreen != 0)
{
PanAndTrackZoomState.EndXInScreen = interactionArguments.ScreenX;
PanAndTrackZoomState.EndYInScreen = interactionArguments.ScreenY;
PointShape upperLeft = ExtentHelper.ToWorldCoordinate(interactionArguments.CurrentExtent, PanAndTrackZoomState.UpperLeftPoint.X, PanAndTrackZoomState.UpperLeftPoint.Y, interactionArguments.MapWidth, interactionArguments.MapHeight);
PointShape lowerRight = ExtentHelper.ToWorldCoordinate(interactionArguments.CurrentExtent, PanAndTrackZoomState.LowRightPoint.X, PanAndTrackZoomState.LowRightPoint.Y, interactionArguments.MapWidth, interactionArguments.MapHeight);
if (mouseMode == MouseMode.TrackZoomIn && PanAndTrackZoomState.IsMouseLeftButtonDown)
{
RectangleShape tempExtent = new RectangleShape(upperLeft, lowerRight);
interactionArguments.CurrentExtent = tempExtent;
trackZoomInLayer.InternalFeatures.Clear();
if (ResetNext)
{
mouseMode = MouseMode.Null;
ResetNext = false;
}
result.DrawThisOverlay = InteractiveOverlayDrawType.Draw;
result.ProcessOtherOverlays = ProcessOtherOverlaysMode.DoNotProcessOtherOverlays;
}
}
PanAndTrackZoomState.IsLeftClickDragKeyPressed = false;
PanAndTrackZoomState.IsRightClickDragKeyPressed = false;
PanAndTrackZoomState.IsMouseLeftButtonDown = false;
PanAndTrackZoomState.IsMouseRightButtonDown = false;
return result;
}
*/
protected override void DrawCore(GeoCanvas canvas)
{
trackZoomInLayer.Open();
trackZoomInLayer.Draw(canvas, new Collection<SimpleCandidate>());
canvas.Flush();
trackZoomInLayer.Close();
}
private RectangleShape GetExtentByTwoPointShapes(PointShape startPointShape, PointShape endPointShape)
{
PointShape upperLeftPointShape = new PointShape(Math.Min(startPointShape.X, endPointShape.X), Math.Max(startPointShape.Y, endPointShape.Y));
PointShape lowerRightPointShape = new PointShape(Math.Max(startPointShape.X, endPointShape.X), Math.Min(startPointShape.Y, endPointShape.Y));
return new RectangleShape(upperLeftPointShape, lowerRightPointShape);
}
}
I’ve seen several references to “it is a bug and will be fixed in the next release”. Can you define a timeframe for this? Next day, next week, or next month?
Ted,
I think we will have a release in this month(June/2009).And in which we will not have a huge structure renew, just fixing some bugs and adding some new features.
If you want, we can send you a Temporary version which with bugs already fixed.
Sorry for the inconvenience.
Yale
Yale,
I have a ‘dog and pony show’ next Wednesday, and the more I can show the happier the boss will be. Can I get a temporary build?
Charles
Charles,
We will send you a Temporary build tomorrow. Sorry for the inconvenience.
Hope you have a wonderful show.
Thanks.
Yale.
What do the interim builds fix? I would be interested as well.
Nelson,
In the interim build, we fixed a bug when we create our own ExtentInteractiveOverlay. In this particular customized ExtentInterativeOverlay,Map extent expected to change in the MapClick / MouseDown event( we do not expect this happen before).
If you are interested in this interim build, just let me know.
Hope this will help you.
Thanks.
Yale
Yale,
I tried to get my code working with the supplied 314 DLL, but I couldn’t get the extent to change. I tried the 307 DLL with the same result. I have backtracked to the 304 DLL for my demonstration. I am also using custom styles, so I have had to create a custom style for all features, including the track and zoom area. I noticed that the code in Post5807Demo.zip doesn’t seem to work with any of the RC1 DLLs. I don’t know if using custom styles is effecting the operation with my code or not, but it is certainly not effecting the operation with the Post5807Demo code. If I could see the Post5807Demo code working with the new DLL I could probably get my code working as well. Could someone take a look at this?
Charles
Charles,
Thanks for your post.
Attachment contains the updated demo which can work in 3.0.314 interim version, But CAN NOT work in the 3.0.307 RC version, because we fixed a bug in 3.0.314 interim version.
In this demo, we changed the default operation action: when Pan, just click and drag, When TrackZoomIn, MapClik to select the first point and move and then MapClick to select the second point without any keyboard needed.
Any more questions just let me know.
Thanks.
Yale
752-Update_Post5807Demo.zip (12.2 KB)
Perhaps I misunderstood, but the extent change in the MapClick does seem to cause a repaint event. I understood that 314 DLL fixed this problem. Was I wrong?
Charles
Charles
Maybe I did not make myself clear enough.
The fix bug in 314 DLL between 307RC version is that in 314 DLL it will fix the map not drawn problem after MapClick event. In 307RC version, after MapClick, it will not draw the map unless you make it OnPaint event happened.
Any more questions just let me know.
Thanks.
Yale
Yale,
But I am now using the 314 DLL and the extent change still doesn't seem to happen. The 314 DLL works fine in the updated Post5807Demo code, but when I change the extent in the MouseClickCore override rather than the MouseUpCore override, the change in extent is not reflected in the WinformsMap control.
Charles