Mitehe

Aug 12, 2010 at 6:01 PM

Hi, I want to know its possible to change the map for a jpg map and add pushpin in there.

Thanks

Coordinator
Aug 25, 2010 at 9:30 PM

Mitehe,

I'm not quite clear on what you are requesting. If you want to provide your own map layer, you can create custom data sources, but this requires some custom work:

http://blogs.msdn.com/b/virtualearth3d/archive/2008/10/12/terrain-imagery-overlays.aspx

Aug 26, 2010 at 2:23 PM

Actually , I have a jpg map( a picture file) , and i want to put pushpin in there but i dont know how to do that..Can you help me please?

Coordinator
Aug 26, 2010 at 2:31 PM

Unless you need  to use Bing Maps it sounds like you just need to overlay a control over another control. This wouldn't need InfoStrat.VE and it would be easier for you to implement yourself.

<Grid>

<Image Source="[your map]" />

<Canvas>

<!-- Your pushpin controls go here -->

</Canvas>

</Grid>

I don't know what type of map you have, but you'll need to figure out a way to convert latitude and longitude (or whatever other measurements your map uses) into pixel positions. Then set the Canvas.Left and Canvas.Top properties appropriately on your pushpin control.

Hope that helps.

Aug 30, 2010 at 7:13 PM
Edited Aug 30, 2010 at 7:13 PM

hi,
 Iim using manipulation to scale my user control . And i want to know how to
apply a minimun scale . I mean , i dont want to reduce my user control  more
than my usercontrol min widht and min height.

Coordinator
Aug 30, 2010 at 7:36 PM

Are you using WPF 4 touch manipulations or a ScatterView?

Aug 30, 2010 at 7:46 PM

here is my application:
xaml:
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Windows;usingSystem.Windows.Controls;usingSystem.Windows.Data;usingSystem.Windows.Documents;usingSystem.Windows.Input;usingSystem.Windows.Media;usingSystem.Windows.Media.Imaging;usingSystem.Windows.Shapes;usingSystem.Windows.Threading;usingMicrosoft.Surface;usingMicrosoft.Surface.Presentation;usingMicrosoft.Surface.Presentation.Controls;usingMicrosoft.Surface.Presentation.Manipulations;usingSystem.Windows.Interop;namespace

{teste2///<summary>///Interaction logic for
SurfaceWindow1.xaml///</summary>publicpartialclassSurfaceWindow1:
SurfaceWindow{///<summary>///Default constructor.///</summary>///#region Class
MembersList<Contact>
downContacts;doublelastExpansionDelta;Affine2DManipulationProcessormanipulationProcessor;Affine2DInertiaProcessorinertiaProcessor;#endregion

#regionProperties#region
{
}ZoomSensitivity DPpublicdoubleZoomSensitivityget{
return(double)GetValue(ZoomSensitivityProperty); }set{
SetValue(ZoomSensitivityProperty, value); }// Using a DependencyProperty as the
backing store for ZoomSensitivity. This enables animation, styling, binding,
etc...publicstaticreadonlyDependencyPropertyZoomSensitivityProperty
=DependencyProperty.Register("ZoomSensitivity", typeof(double),
typeof(SurfaceWindow1), newUIPropertyMetadata(6.0));#endregion
#region
{
}PanSensitivity DPpublicdoublePanSensitivityget{
return(double)GetValue(PanSensitivityProperty); }set{
SetValue(PanSensitivityProperty, value); }// Using a DependencyProperty as the
backing store for PanSensitivity. This enables animation, styling, binding,
etc...publicstaticreadonlyDependencyPropertyPanSensitivityProperty
=DependencyProperty.Register("PanSensitivity", typeof(double),
typeof(SurfaceWindow1), newUIPropertyMetadata(1.0));#endregion
#region
{
}TiltSensitivity DPpublicdoubleTiltSensitivityget{
return(double)GetValue(TiltSensitivityProperty); }set{
SetValue(TiltSensitivityProperty, value); }// Using a DependencyProperty as the
backing store for PanSensitivity. This enables animation, styling, binding,
etc...publicstaticreadonlyDependencyPropertyTiltSensitivityProperty
=DependencyProperty.Register("TiltSensitivity", typeof(double),
typeof(SurfaceWindow1), newUIPropertyMetadata(0.5));#endregion 
 #endregion{
InitializeComponent();
lastExpansionDelta = 0;
downContacts =
targetImage.AddHandler(
targetImage.AddHandler(
targetImage.AddHandler(publicSurfaceWindow1()newList<Contact>();this.manipulationProcessor
=
newAffine2DManipulationProcessor(Affine2DManipulations.TranslateX|Affine2DManipulations.TranslateY|Affine2DManipulations.Scale
,this, false);this.manipulationProcessor.Affine2DManipulationCompleted +=
newEventHandler<Affine2DOperationCompletedEventArgs>(manipulationProcessor_Affine2DManipulationCompleted);this.manipulationProcessor.Affine2DManipulationDelta
+=
newEventHandler<Affine2DOperationDeltaEventArgs>(manipulationProcessor_Affine2DManipulationDelta);this.manipulationProcessor.Affine2DManipulationStarted
+=
newEventHandler<Affine2DOperationStartedEventArgs>(manipulationProcessor_Affine2DManipulationStarted);this.inertiaProcessor
= newAffine2DInertiaProcessor();this.inertiaProcessor.Affine2DInertiaDelta +=
newEventHandler<Affine2DOperationDeltaEventArgs>(inertiaProcessor_Affine2DInertiaDelta);this.inertiaProcessor.Affine2DInertiaCompleted
+=
newEventHandler<Affine2DOperationCompletedEventArgs>(inertiaProcessor_Affine2DInertiaCompleted);Contacts.PreviewContactDownEvent,
newContactEventHandler(targetImage_PreviewContactDown));Contacts.PreviewContactChangedEvent,
,
newContactEventHandler(targetImage_PreviewContactChanged));Contacts.PreviewContactUpEvent,
newContactEventHandler(targetImage_PreviewContactUp));// Add handlers for
Application activation eventsAddActivationHandlers();
}
 ///<summary>///Occurs when the window is about to close. ///</summary>///<param
name="e"></param>{protectedoverridevoidOnClosed(EventArgse)base.OnClosed(e);//
Remove handlers for Application activation eventsRemoveActivationHandlers();
}///<summary>///Adds handlers for Application activation
events.///</summary>{privatevoidAddActivationHandlers()// Subscribe to surface
application activation events}ApplicationLauncher.ApplicationActivated +=
OnApplicationActivated;ApplicationLauncher.ApplicationPreviewed +=
OnApplicationPreviewed;ApplicationLauncher.ApplicationDeactivated +=
OnApplicationDeactivated;///<summary>///Removes handlers for Application
activation events.///</summary>{privatevoidRemoveActivationHandlers()//
Unsubscribe from surface application activation
events}ApplicationLauncher.ApplicationActivated -=
OnApplicationActivated;ApplicationLauncher.ApplicationPreviewed -=
OnApplicationPreviewed;ApplicationLauncher.ApplicationDeactivated -=
OnApplicationDeactivated;///<summary>///This is called when application has been
activated.///</summary>///<param name="sender"></param>///<param
name="e"></param>{privatevoidOnApplicationActivated(objectsender,
EventArgse)//TODO: enable audio, animations here}///<summary>///This is called
when application is in preview mode.///</summary>///<param
name="sender"></param>///<param
name="e"></param>{privatevoidOnApplicationPreviewed(objectsender,
EventArgse)//TODO: Disable audio here if it is enabled//TODO: optionally enable
animations here}///<summary>///This is called when application has been
deactivated.///</summary>///<param name="sender"></param>///<param
name="e"></param>{privatevoidOnApplicationDeactivated(objectsender,
EventArgse)//TODO: disable audio, animations here}
 #region
{
}
{
}
{
}
{
ProcessManipulationInertiaDelta(e);
}Inertia Processor Event
HandlersvoidinertiaProcessorZoom_Affine2DInertiaCompleted(objectsender,
Affine2DOperationCompletedEventArgse)voidinertiaProcessorZoom_Affine2DInertiaDelta(objectsender,
Affine2DOperationDeltaEventArgse)voidinertiaProcessor_Affine2DInertiaCompleted(objectsender,
,
Affine2DOperationCompletedEventArgse)voidinertiaProcessor_Affine2DInertiaDelta(objectsender,
Affine2DOperationDeltaEventArgse)#endregion
#region
{
inertiaProcessor.End();
}
{
ProcessManipulationInertiaDelta(e);
}
 
{
containerRect.Width = 1024;
containerRect.Height = 798;
 
 
 
 
 
 
 
 
 
 
 
 
{
matrix = transformMatrix.Matrix;
}
matrix.Translate(-e.Delta.X, -e.Delta.Y);
 
 
 
{
 
 
 
 
 
 
transformCenter = matrix.Transform(transformCenter);
matrix.RotateAt(e.RotationDelta, transformCenter.X, transformCenter.Y);
matrix.ScaleAt(e.ScaleDelta, e.ScaleDelta, transformCenter.X,
transformCenter.Y);
}
 
 
targetImage.RenderTransform =
 
}
{
}Manipulation Processor Event
HandlersvoidmanipulationProcessor_Affine2DManipulationStarted(objectsender,
Affine2DOperationStartedEventArgse)voidmanipulationProcessor_Affine2DManipulationDelta(objectsender,
Affine2DOperationDeltaEventArgse)privatevoidProcessManipulationInertiaDelta(Affine2DOperationDeltaEventArgse)RectcontainerRect
t = newRect(this.RenderSize);UIElementcontent = this.targetImage
asUIElement;Matrixmatrix = newMatrix();MatrixTransformtransformMatrix =
targetImage.RenderTransform asMatrixTransform;if(transformMatrix !=
null)if(this.targetImage isFrameworkElement)FrameworkElementframeworkElement =
this.targetImage asFrameworkElement;PointtransformCenter =
this.TranslatePoint(e.ManipulationOrigin,
frameworkElement);newMatrixTransform(matrix);voidmanipulationProcessor_Affine2DManipulationCompleted(objectsender,
Affine2DOperationCompletedEventArgse)#endregion
#region
{
}
{
position.Y < 0 ||
position.X > targetImage.Width ||
position.Y > targetImage.Height)
{UI Event HandlersprivatevoidtargetImage_PreviewContactDown(objectsender,
ContactEventArgse)privatevoidtargetImage_PreviewContactChanged(objectsender,
ContactEventArgse)if(!e.Contact.IsFingerRecognized)return;Pointposition =
e.Contact.GetPosition(this);if(position.X < 0 ||//
e.Contact.Capture(targetImage,
System.Windows.Input.CaptureMode.None);e.Contact.Capture(
 
downContacts.Remove(e.Contact);
}this, CaptureMode.None);if(downContacts.Contains(e.Contact))else{//
e.Contact.Capture(targetImage,
System.Windows.Input.CaptureMode.SubTree);e.Contact.Capture(
manipulationProcessor.BeginTrack(e.Contact);
e.Handled =
downContacts.Add(e.Contact);
 
}
}
{this,
CaptureMode.SubTree); true;if(!downContacts.Contains(e.Contact))privatevoidtargetImage_PreviewContactUp(objectsender,
ContactEventArgse)if(!e.Contact.IsFingerRecognized)return;//e.Contact.Capture(targetImage,
, System.Windows.Input.CaptureMode.None);e.Contact.Capture(
downContacts.Remove(e.Contact);
}
 this, CaptureMode.None);#endregion
 }
}
 
 
 <s:SurfaceWindowx:Class="teste2.SurfaceWindow1"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:s="http://schemas.microsoft.com/surface/2008"xmlns:l="clr-namespace:teste2"Title="teste2"><s:SurfaceWindow.Resources><ImageBrushx:Key="WindowBackground"Stretch="None"Opacity="0.6"ImageSource="pack://application:,,,/Resources/WindowBackground.jpg"/></s:SurfaceWindow.Resources><GridBackground="{StaticResourceWindowBackground}"Name="tt"
><ViewboxName="targetImage"Width="1024"Height="798"MinWidth="1024"MinHeight="798"><l:testcontrolWidth="1024
4
"Height="798"MinHeight="798"MinWidth="1024"></l:testcontrol></Viewbox></</Grid>s:SurfaceWindow>



Aug 30, 2010 at 7:48 PM

im using Affine2DManipulationProcessor

Coordinator
Aug 30, 2010 at 7:53 PM

Sorry, that source code is badly formatted. I cannot read it without spaces.

In the manipulation delta event you just need to check to see if the size or scale is below a certain threshold. If so, then don't let it decrease the size any more.

Aug 30, 2010 at 7:56 PM

 

 

 

 i do that but it not working

 

private void ProcessManipulationInertiaDelta(Affine2DOperationDeltaEventArgs e)

containerRect.Width = 1024;

containerRect.Height = 798;

UIElement content = this.targetImage as UIElement;

 Matrix matrix = new Matrix();

{

 

 

Rect containerRect = new Rect(this.RenderSize);

MatrixTransform transformMatrix = content.RenderTransform as MatrixTransform;

{

matrix = transformMatrix.Matrix;

}

matrix.Translate(-e.Delta.X, -e.Delta.Y);

 

 

 

 

 

 

 

 

 

 

 

if (this.targetImage is FrameworkElement)

 

}

{

targetImage.RenderTransform =

 

new MatrixTransform(matrix);

 

 

 

 

}

 

 

 

if (targetImage.ActualWidth * e.ScaleDelta >= 1024)

 

matrix.ScaleAt(e.ScaleDelta, e.ScaleDelta, transformCenter.X, transformCenter.Y);

 

 

 

zoomWidht = 1024;

 

 

 

Console.WriteLine("Scale delta: " + e.ScaleDelta + " Rotate delta: " + e.RotationDelta);

transformCenter = matrix.Transform(transformCenter);

matrix.RotateAt(e.RotationDelta, transformCenter.X, transformCenter.Y);

 

 

 

// var newScale = scale.ScaleX * e.ScaleDelta;

 

 

 

 

 

Point transformCenter = this.TranslatePoint(e.ManipulationOrigin, this.targetImage);

{

 

 

 

 

 

FrameworkElement frameworkElement = this.targetImage as FrameworkElement;

 

 

if (transformMatrix != null)

Aug 30, 2010 at 8:05 PM

 

private void ProcessManipulationInertiaDelta(Affine2DOperationDeltaEventArgs e)

{

 

Rect containerRect = new Rect(this.RenderSize);

 

UIElement content = this.targetImage as UIElement;

 

Matrix matrix = new Matrix();

 

MatrixTransform transformMatrix = content.RenderTransform as MatrixTransform;

 

if (transformMatrix != null)

{

matrix = transformMatrix.Matrix;

}

matrix.Translate(-e.Delta.X, -e.Delta.Y);

 

if (this.targetImage is FrameworkElement)

{

 

FrameworkElement frameworkElement = this.targetImage as FrameworkElement;

 

Point transformCenter = this.TranslatePoint(e.ManipulationOrigin, this.targetImage);

transformCenter = matrix.Transform(transformCenter);

matrix.RotateAt(e.RotationDelta, transformCenter.X, transformCenter.Y);

matrix.ScaleAt(e.ScaleDelta, e.ScaleDelta, transformCenter.X, transformCenter.Y);

 

 

Console.WriteLine("Scale delta: " + e.ScaleDelta + " Rotate delta: " + e.RotationDelta);

}

 

if (targetImage.ActualWidth * e.ScaleDelta >= 1024)

{

targetImage.RenderTransform =

new MatrixTransform(matrix);

}

Coordinator
Aug 30, 2010 at 8:16 PM

The key lines is:

if (targetImage.ActualWidth * e.ScaleDelta >= 1024)

 

e.ScaleDelta contains only the change in delta for this particular event. Multiplying targetImage.ActualWidth by e.ScaleDelta will not result in the new total width. You need to check the total change in width.

Here is some untested, non-optimal code to do this:

Snippet

          MatrixTransform transformMatrix;
          Matrix matrix = transformMatrix.Matrix;
          matrix.Transform(...);
          matrix.RotateAt(...);

          Matrix proposedMatrix = new Matrix(matrix.M11, matrix.M12, matrix.M21, matrix.M22, matrix.OffsetX, matrix.OffsetY);
          proposedMatrix.ScaleAt(e.ScaleDelta, e.ScaleDelta, transformCenter.X, transformCenter.Y);
          Point newSize = proposedMatrix.Transform(new Point(targetImage.ActualWidth, targetImage.ActualHeight))
              
          if (newSize.X > minSizeX && newSize.Y > minSizeY)
          {
              matrix = proposedMatrix;
          }

          targetImage.RenderTransform = new MatrixTransform(matrix);
Aug 30, 2010 at 8:31 PM

Thanks a  lot...its working

Coordinator
Aug 30, 2010 at 8:33 PM

Great!

Sep 1, 2010 at 1:45 PM

HI,

when i scale after reducing, my targetImage doesn't come to his original position. Its possible that the targetImage come to his original position after scalling?

Sep 1, 2010 at 2:20 PM

another question , how to limited the translation. like i just want to trnslate between x1 and x2    and   y1 and y2

Coordinator
Sep 1, 2010 at 2:32 PM

If you don't want the targetImage to move from its original position, then you can just not translating the matrix by the translation value.

You can limit the translation by using matrix.Transform() on the center point and testing if it is in your range.

As the image is scaled up you could decrease the allowable translation range and force the image back into range.

Sep 1, 2010 at 3:06 PM

it is something like that to limited the translation ...sorry im new with surface and wpf and i dont know very well

 

Point centerPoint = proposedMatrix.Transform(new Point((targetImage.Width / 2), (targetImage.Height / 2)));

 

if (centerPoint.X < this.targetImage.ActualWidth && centerPoint.Y < this.targetImage.ActualHeight)

{

proposedMatrix.Translate(-e.Delta.X, -e.Delta.Y);

}

Coordinator
Sep 1, 2010 at 5:12 PM

It might work, try it and see. You might want to test to make sure the centerPoint.X and .Y is greater than a minimum value as well.

Sep 1, 2010 at 6:24 PM

Still doesnt work when a i do it:

FrameworkElement frameworkElement = this.targetImage as FrameworkElement;

Point transformCenter = this.TranslatePoint(e.ManipulationOrigin,frameworkElement);

               transformCenter = matrix.Transform(transformCenter);

               Matrix proposedMatrix = new Matrix(matrix.M11, matrix.M12, matrix.M21, matrix.M22, matrix.OffsetX, matrix.OffsetY);

               proposedMatrix.ScaleAt(e.ScaleDelta, e.ScaleDelta, transformCenter.X, transformCenter.Y);

               Point centre = new Point(targetImage.ActualWidth / 2.0, targetImage.ActualHeight / 2.0);

               centre = proposedMatrix.Transform(centre);

               if (centre.X > this.targetImage.ActualWidth&& centre.Y>this.targetImage.ActualHeight)

               {

                   proposedMatrix.Translate(-e.Delta.X, -e.Delta.Y);

               }

                

               Point newSize = proposedMatrix.Transform(new Point(targetImage.ActualWidth, targetImage.ActualHeight));

              

               if (newSize.X > this.targetImage.ActualWidth && newSize.Y > this.targetImage.ActualHeight)

               {

                   matrix = proposedMatrix;

               }

           }

           targetImage.RenderTransform = new MatrixTransform(matrix);