I have use WCF Services in an app.
I draw the line when going from 1 lists the coordinates returned from WCF. Then draw the wrong path. While Windows Phone 7 displays properly, using Polyline.
Shown below are the results that I got wrong:
And I want to display:
This is the code that I handle to draw:
void wcl_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
try
{
if (string.IsNullOrEmpty(e.Result) || e.Error != null)
{
MessageBox.Show("Lỗi kết nối! Hãy thử lại");
waitingPage.Visibility = System.Windows.Visibility.Collapsed;
return;
}
XuLyToaDo route = XuLyToaDo.TaoMapRoute();
//Lay ds diem ve
string Ketqua = XuLyToaDo.DanhSachDiemVe(e.Result);
string[] kq = Ketqua.Split('&');
//Lay thong tin toa do
XuLyToaDo routePushpin = XuLyToaDo.TaoMapRoute();
XuLyToaDo routePolyline = XuLyToaDo.TaoMapRoute();
//MessageBox.Show(kq[0]);
//MessageBox.Show(kq[1]);
//MessageBox.Show(kq[2]);
//Tao ds toa do
List<GeoCoordinate> lsToaDoPushpin = routePushpin.TaoDSToaDo(kq[0]);
List<GeoCoordinate> lsToaDoRoute = routePushpin.TaoDSToaDo(kq[1]);
// Lay ds ten duong
string[] MangTenDiaChi = routePushpin.TaoDSDuong(kq[2]);
if (lsToaDoPushpin == null)
{
MessageBox.Show("Không có thông tin");
waitingPage.Visibility = System.Windows.Visibility.Collapsed;
return;
}
for (int i = 0; i < lsToaDoPushpin.Count - 1; i++)
{
AddRoute(lsToaDoPushpin[i], Colors.Blue);
}
//ve duong di
for (int i = 0; i < lsToaDoPushpin.Count - 2; i++)
{
AddRouteMap(lsToaDoPushpin[i], lsToaDoPushpin[i + 1]);
}
//ve duong di
//MyRouteQuery = new RouteQuery()
//{
// TravelMode = TravelMode.Driving,
// Waypoints = lsToaDoRoute
//};
//MyRouteQuery.QueryCompleted += MyRouteQuery_QueryCompleted;
//MyRouteQuery.QueryAsync();
//Them danh sach tram
int k = 0;
foreach (GeoCoordinate geo in lsToaDoPushpin)
{
if (k == lsToaDoPushpin.Count() - 1)
break;
Pushpin pus = new Pushpin();
string str = "Direc_" + k;
pus.Template = Maps.App.Current.Resources[str] as ControlTemplate;
pus.Tag = k;
pus.Content = k.ToString() + ". " + MangTenDiaChi[k];
pus.Tap += new EventHandler<System.Windows.Input.GestureEventArgs>(pus_Tap);
MyMap.Layers.Add(new MapLayer()
{
new MapOverlay()
{
GeoCoordinate = geo,
PositionOrigin = new Point(0.5,0.5),
Content = pus
}
});
k++;
}
MyMap.Center = lsToaDoPushpin[0];
MyMap.ZoomLevel = 15;
waitingPage.Visibility = System.Windows.Visibility.Collapsed;
}
catch (Exception ex)
{
MessageBox.Show("Lỗi kết nối. Hãy thử lại!!" + ex.Message);
}
}
private void AddRouteMap(GeoCoordinate g1, GeoCoordinate g2)
{
List<GeoCoordinate> lsRoute = new List<GeoCoordinate>();
lsRoute.Add(g1);
lsRoute.Add(g2);
MyRouteQuery = new RouteQuery()
{
TravelMode = TravelMode.Walking,
Waypoints = lsRoute
};
MyRouteQuery.QueryCompleted += MyRouteQuery_QueryCompleted;
MyRouteQuery.QueryAsync();
}
void MyRouteQuery_QueryCompleted(object sender, QueryCompletedEventArgs<Route> e)
{
if (e.Error == null)
{
if (MyMapRoute != null)
AddlstMapRoute(MyMapRoute);
MyRoute = e.Result;
MyMapRoute = new MapRoute(MyRoute);
MyMap.AddRoute(MyMapRoute);
}
}
private void AddlstMapRoute(MapRoute maproute)
{
lsMapRoute.Add(maproute);
}
private void AddRoute(GeoCoordinate geo, Color color)
{
MyMap.Layers.Add(new MapLayer()
{
new MapOverlay()
{
GeoCoordinate = geo,
PositionOrigin = new Point(0.5,0.5),
Content = new Ellipse
{
Fill = new SolidColorBrush(color),
Width =5,
Height = 5
}
}
});
}
void pus_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
e.Handled = true;
Pushpin pus = sender as Pushpin;
ToolTipService.SetToolTip(pus, new ToolTip()
{
DataContext = pus,
Style = Application.Current.Resources["CustomInfoboxStyle"] as Style
});
MessageBox.Show(pus.Content.ToString(), "Thông tin trạm", MessageBoxButton.OK);
}
This is the place where I create database:
How can I fix this?
i guess its due to the fact that your travelmode is set to walking and google seems to think that walking there isnt allowed, so it takes the next possible way. try change the travelmode to driving or so.
greetings lars
Related
I can not figure out how I get more XML file from the language images,
In the image here you will look at setupItems how it is built
Here it explains how I build the missing XML file but I do not understand how I build it properly that will work for me on the site
public function init(param1:int) : void
{
var _loc2_:String = null;
this.itemHolder.addChild(this.hairHolder);
this.itemHolder.addChild(this.shirtHolder);
this.shirtHolder.visible = false;
this.itemHolder.addChild(this.pantsHolder);
this.pantsHolder.visible = false;
this.itemHolder.addChild(this.shoesHolder);
this.shoesHolder.visible = false;
this.activeHolder = this.hairHolder;
this.initButtons();
this.randomTimer = new Timer(this.randomTimerInitDelay,this.randomTimerCount);
this.randomTimer.addEventListener(TimerEvent.TIMER,this.changeRandomClothes,false,0,true);
this.xml = new XML();
if(param1 == 1)
{
_loc2_ = "boyItems.xml";
}
else if(param1 == 2)
{
_loc2_ = "girlItems.xml";
}
this.xmlLoader = new URLLoader(new URLRequest("./website/common/register/xmls/" + _loc2_));
this.xmlLoader.addEventListener(Event.COMPLETE,this.xmlLoaded);
this.xmlLoader.addEventListener(IOErrorEvent.IO_ERROR,this.errorLoadingXml);
}
another code
private function xmlLoaded(param1:Event) : void
{
this.xmlLoader.removeEventListener(Event.COMPLETE,this.xmlLoaded);
this.xmlLoader.removeEventListener(IOErrorEvent.IO_ERROR,this.errorLoadingXml);
this.xml = XML(this.xmlLoader.data);
Register.AVATAR_HAIR = this.xml.hair.child(0).#id;
var _loc2_:int = Math.random() * 2 + 1;
this.bubble.gotoAndStop("hair_" + Register.language + _loc2_);
this.setupItems(this.xml.hair,this.hairItems,this.hairHolder);
this.setupItems(this.xml.shirt,this.shirtItems,this.shirtHolder);
this.setupItems(this.xml.pants,this.pantsItems,this.pantsHolder);
this.setupItems(this.xml.shoes,this.shoesItems,this.shoesHolder);}
private function setupItems(param1:*, param2:Array, param3:Sprite) : void
{
var _loc9_:* = undefined;
var _loc10_:Item = null;
var _loc4_:int = 54.5;
var _loc5_:Number = 64.5;
var _loc6_:*;
var _loc7_:int = (_loc6_ = param1).children().length();
var _loc8_:int = 0;
while(_loc8_ < _loc7_)
{
_loc9_ = _loc6_.child(_loc8_);
(_loc10_ = new Item()).x = _loc4_;
_loc4_ += this.itemSpacing;
_loc10_.y = _loc5_;
_loc10_.loadItem(_loc9_.#type,_loc9_.#ordinal,_loc9_.#id,_loc9_.#inventoryType,Register.pathToItemsFolder);
param2.push(_loc10_);
param3.addChild(_loc10_);
_loc8_++;
}
}
This is the loadItem file:
(Maybe here you can see how I build the XML files)
public function loadItem(param1:int, param2:int, param3:int, param4:int, param5:String) : void
{
this.type = param1;
this.ordinal = param2;
this.id = param3;
this.itemImage = new ImageItemNoCache(param1,param2,param3,param4,null,null,param5);
this.itemImage.mouseEnabled = false;
this.itemImage.mouseChildren = false;
this.itemImage.addEventListener(ImageItem.DATA_LOADED,this.positionImage,false,0,true);
addChild(this.itemImage);
addEventListener(MouseEvent.CLICK,this.clickedMe,false,0,true);
}
Code for ImageItemNoCache:
public class ImageItemNoCache extends ImageItem
{
private var textData:Object;
private var itemData:Object;
private var pathToItemsFolder:String;
public function ImageItemNoCache(param1:int, param2:int, param3:int, param4:int, param5:Object = null, param6:Object = null, param7:String = ".")
{
this.textData = param5;
this.itemData = param6;
this.pathToItemsFolder = param7;
super(param1,param2,param3,param4);
}
override protected function getImageItemData(param1:int, param2:int = -1, param3:int = -1, param4:int = -1) : ImageItemData
{
return new ImageItemDataNoCache(param1,param2,param3,param4,this.textData,this.itemData,this.pathToItemsFolder);
}
override public function clone() : DisplayItem
{
return new ImageItemNoCache(getType(),getOrdinal(),getId(),getInventoryType(),this.textData,this.itemData,this.pathToItemsFolder);
}
}
I'm beginner to windows phone development and i done swiping the images in carousel view in portrait orientation and i tried for landscape orintation which is not done succesfully.please any one help me to resolve this issue.
TouchPoint _first;
private List<TList> _pivotList;
public Pivot()
{
InitializeComponent();
Loaded += pivot_Loaded;
Touch.FrameReported += Touch_FrameReported;
}
private void Touch_FrameReported(object sender, TouchFrameEventArgs e)
{
TouchPoint mainTouch = e.GetPrimaryTouchPoint(null);
if (mainTouch.Action == TouchAction.Down)
_first = mainTouch;
else if (mainTouch.Action == TouchAction.Up)
{
var xDelta = mainTouch.Position.X - _first.Position.X;
var yDelta = Math.Abs(mainTouch.Position.Y - _first.Position.Y);
if (yDelta > Math.Abs(xDelta))
return;
if (Math.Abs(xDelta - 0) > 10)
{
var currentIndex = pivotList.SelectedIndex;
int noOfPivotItems = pivotList.Items.Count;
currentIndex = (xDelta < 0) ?
++currentIndex % noOfPivotItems :
(--currentIndex + noOfPivotItems) % noOfPivotItems;
pivotList.SelectedIndex = currentIndex;
}
}
}
here is code for DisplayOrientations .
public Pivot()
{
InitializeComponent();
Loaded += pivot_Loaded;
this.navigationHelper = new NavigationHelper(this);
Windows.Graphics.Display.DisplayInformation.AutoRotationPreferences = Windows.Graphics.Display.DisplayOrientations.Landscape;
Windows.Graphics.Display.DisplayInformation.AutoRotationPreferences = Windows.Graphics.Display.DisplayOrientations.PortraitFlipped;
}
I am working on an application which can take input thru touch screen using mouse or stylus.. Found that <InkCanvas> works really great for me, but Windows Store app project does not recognize/support <InkCanvas> tag.
Does any came across similar kind of requirement and scenario.
Any suggestion.
Of course, one of them is but it is not as flexible as <InkCanvas>
Use this control in xaml like: <ctrl:InkCanvas x:Name="inkCanvas" />
Don't forget to reference 'ctrl' like: xmlns:ctrl="using:MyAppNamespace"
using System;
using System.Collections.Generic;
using Windows.Devices.Input;
using Windows.Foundation;
using Windows.UI;
using Windows.UI.Input;
using Windows.UI.Input.Inking;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Shapes;
using System.Linq;
using System.Threading.Tasks;
using Windows.Storage;
using Windows.Storage.Streams;
using Windows.UI.Xaml.Media.Imaging;
using System.Runtime.InteropServices.WindowsRuntime;
namespace MyAppNamespace
{
public class InkCanvas : Canvas
{
InkManager m_InkManager = new Windows.UI.Input.Inking.InkManager();
private uint m_PenId;
private uint _touchID;
private Point _previousContactPt;
private Point currentContactPt;
private double x1;
private double y1;
private double x2;
private double y2;
private Color m_CurrentDrawingColor = Colors.Black;
private double m_CurrentDrawingSize = 4;
public List<InkStroke> Strokes { get { return m_InkManager.GetStrokes().ToList(); } }
public InkCanvas()
{
m_InkManager.Mode = Windows.UI.Input.Inking.InkManipulationMode.Inking;
SetDefaults(m_CurrentDrawingSize, m_CurrentDrawingColor);
this.PointerPressed += new PointerEventHandler(OnCanvasPointerPressed);
this.PointerMoved += new PointerEventHandler(OnCanvasPointerMoved);
this.PointerReleased += new PointerEventHandler(OnCanvasPointerReleased);
this.PointerExited += new PointerEventHandler(OnCanvasPointerReleased);
}
public void Clear()
{
this.Children.Clear();
var strokes = m_InkManager.GetStrokes();
for (int i = 0; i < strokes.Count; i++)
strokes[i].Selected = true;
m_InkManager.DeleteSelected();
}
public async Task<byte[]> GetBytes()
{
var bytes = new byte[0];
if (Strokes.Count > 0)
{
var tempFile = await ApplicationData.Current.LocalFolder.CreateFileAsync(Guid.NewGuid().ToString() + ".jpg");
var writeStream = await tempFile.OpenAsync(FileAccessMode.ReadWrite);
await m_InkManager.SaveAsync(writeStream);
await writeStream.FlushAsync();
var reader = new DataReader(writeStream.GetInputStreamAt(0));
bytes = new byte[writeStream.Size];
await reader.LoadAsync((uint)writeStream.Size);
reader.ReadBytes(bytes);
reader.DetachStream();
await tempFile.DeleteAsync();
}
return bytes;
}
public async Task<BitmapImage> GetBitmapImage()
{
var bitmapImage = new BitmapImage();
var bytes = await GetBytes();
if (bytes.Length > 0)
{
using (var stream = new InMemoryRandomAccessStream())
{
// For AsBuffer manually add [ using System.Runtime.InteropServices.WindowsRuntime ];
await stream.WriteAsync(bytes.AsBuffer());
stream.Seek(0);
bitmapImage.SetSource(stream);
}
}
return bitmapImage;
}
#region Pointer Event Handlers
public void OnCanvasPointerReleased(object sender, PointerRoutedEventArgs e)
{
if (e.Pointer.PointerId == m_PenId)
{
Windows.UI.Input.PointerPoint pt = e.GetCurrentPoint(this);
// Pass the pointer information to the InkManager.
m_InkManager.ProcessPointerUp(pt);
}
else if (e.Pointer.PointerId == _touchID)
{
// Process touch input
}
_touchID = 0;
m_PenId = 0;
e.Handled = true;
}
private void OnCanvasPointerMoved(object sender, PointerRoutedEventArgs e)
{
if (e.Pointer.PointerId == m_PenId)
{
PointerPoint pt = e.GetCurrentPoint(this);
// Render a red line on the canvas as the pointer moves.
// Distance() is an application-defined function that tests
// whether the pointer has moved far enough to justify
// drawing a new line.
currentContactPt = pt.Position;
x1 = _previousContactPt.X;
y1 = _previousContactPt.Y;
x2 = currentContactPt.X;
y2 = currentContactPt.Y;
var color = m_CurrentDrawingColor;
var size = m_CurrentDrawingSize;
if (Distance(x1, y1, x2, y2) > 2.0)
{
Line line = new Line()
{
X1 = x1,
Y1 = y1,
X2 = x2,
Y2 = y2,
StrokeThickness = size,
Stroke = new SolidColorBrush(color)
};
_previousContactPt = currentContactPt;
// Draw the line on the canvas by adding the Line object as
// a child of the Canvas object.
this.Children.Add(line);
}
// Pass the pointer information to the InkManager.
m_InkManager.ProcessPointerUpdate(pt);
}
else if (e.Pointer.PointerId == _touchID)
{
// Process touch input
}
}
private double Distance(double x1, double y1, double x2, double y2)
{
double d = 0;
d = Math.Sqrt(Math.Pow((x2 - x1), 2) + Math.Pow((y2 - y1), 2));
return d;
}
public void OnCanvasPointerPressed(object sender, PointerRoutedEventArgs e)
{
// Get information about the pointer location.
PointerPoint pt = e.GetCurrentPoint(this);
_previousContactPt = pt.Position;
// Accept input only from a pen or mouse with the left button pressed.
PointerDeviceType pointerDevType = e.Pointer.PointerDeviceType;
if (pointerDevType == PointerDeviceType.Pen ||
pointerDevType == PointerDeviceType.Mouse &&
pt.Properties.IsLeftButtonPressed)
{
// Pass the pointer information to the InkManager.
m_InkManager.ProcessPointerDown(pt);
m_PenId = pt.PointerId;
e.Handled = true;
}
else if (pointerDevType == PointerDeviceType.Touch)
{
// Process touch input
}
}
#endregion
#region Mode Functions
// Change the color and width in the default (used for new strokes) to the values
// currently set in the current context.
private void SetDefaults(double strokeSize, Color color)
{
var newDrawingAttributes = new InkDrawingAttributes();
newDrawingAttributes.Size = new Size(strokeSize, strokeSize);
newDrawingAttributes.Color = color;
newDrawingAttributes.FitToCurve = true;
m_InkManager.SetDefaultDrawingAttributes(newDrawingAttributes);
this.Background = new SolidColorBrush(Colors.White);
}
#endregion
}
}
You use the InkManager class in WinRT instead of WPF's InkCanvas. I think you might need to use your own Canvas control with some Shapes (Polyline?) and handle the Pointer~ events yourself, but I haven't done it myself so I can't say for sure.
I have a sort of drawing app. The lines are drawn on the touch input.
void Touch_FrameReported(object sender, TouchFrameEventArgs e)
{
int pointsNumber = e.GetTouchPoints(InkCanvas2).Count;
TouchPointCollection pointCollection = e.GetTouchPoints(InkCanvas2);
for (int i = 0; i < pointsNumber; i++)
{
if (pointCollection[i].Action == TouchAction.Down)
{
preXArray[i] = pointCollection[i].Position.X;
preYArray[i] = pointCollection[i].Position.Y;
}
if (pointCollection[i].Action == TouchAction.Move)
{
Line line = new Line();
line.X1 = preXArray[i];
line.Y1 = preYArray[i];
line.X2 = pointCollection[i].Position.X;
line.Y2 = pointCollection[i].Position.Y;
line.Stroke = StrokeColorBrush;
line.Fill = StrokeColorBrush;
line.StrokeThickness = StrokeWidth;
line.StrokeDashCap = PenLineCap.Round;
line.StrokeStartLineCap = PenLineCap.Round;
line.StrokeEndLineCap = PenLineCap.Round;
InkCanvas2.Children.Add(line);
preXArray[i] = pointCollection[i].Position.X;
preYArray[i] = pointCollection[i].Position.Y;
Brush aSolidBrush = new SolidColorBrush(Colors.Black);
}
}
Mouse events
void InkCanvas2_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
currentPoint = e.GetPosition(InkCanvas2);
oldPoint = currentPoint;
}
void InkCanvas2_MouseMove(object sender, MouseEventArgs e)
{
currentPoint = e.GetPosition(this.InkCanvas2);
Line line = new Line() { X1 = currentPoint.X, Y1 = currentPoint.Y, X2 = oldPoint.X, Y2 = oldPoint.Y };
line.Stroke = StrokeColorBrush;
line.StrokeThickness = StrokeWidth;
line.StrokeStartLineCap = PenLineCap.Round;
line.StrokeEndLineCap = PenLineCap.Round;
line.StrokeLineJoin = PenLineJoin.Round;
this.InkCanvas2.Children.Add(line);
oldPoint = currentPoint;
}
I have done clear all by
InkCanvas2.Children.Clear();
now Im trying to implement a eraser function, then i draw over the line, it should erase those parts.
I tried changing color to transparent which does not do the trick. Any suggestions?
You can do something like this:
inkCanvas2.EditingMode = InkCanvasEditingMode.EraseByPoint;
I saw this code but it only works if the destination is specified by search!
I need to navigate to a specific position using latitude and longitude .
GeocodeQuery Mygeocodequery = null;
Mygeocodequery = new GeocodeQuery();
Mygeocodequery.SearchTerm = "Seattle, WA";
Mygeocodequery.GeoCoordinate = new GeoCoordinate(MyGeoPosition.Coordinate.Latitude,MyGeoPosition.Coordinate.Longitude);
Mygeocodequery.QueryCompleted += Mygeocodequery_QueryCompleted;
Mygeocodequery.QueryAsync();
void Mygeocodequery_QueryCompleted(object sender, QueryCompletedEventArgs<IList<MapLocation>> e)
{
if (e.Error == null)
{
MyQuery = new RouteQuery();
MyCoordinates.Add(e.Result[0].GeoCoordinate);
MyQuery.Waypoints = MyCoordinates;
MyQuery.QueryCompleted += MyQuery_QueryCompleted;
MyQuery.QueryAsync();
Mygeocodequery.Dispose();
}
}
void MyQuery_QueryCompleted(object sender, QueryCompletedEventArgs<Route> e)
{
if (e.Error == null)
{
Route MyRoute = e.Result;
MapRoute MyMapRoute = new MapRoute(MyRoute);
MyMap.AddRoute(MyMapRoute);
MyQuery.Dispose();
}
}
Here's a sample code (assuming you already have your source and target coordinates).
public partial class Foo : PhoneApplicationPage
{
List<GeoCoordinate> MyCoordinates = new List<GeoCoordinate>();
public Foo()
{
InitializeComponent();
}
private void SetMapCoordinates()
{
MyCoordinates.Add(new GeoCoordinate(Target.Latitude, Target.Longitude));
MyCoordinates.Add(new GeoCoordinate(Source.Latitude, Source.Longitude));
DrawMyRoute();
}
void MyRoute()
{
MyQuery = new RouteQuery();
MyQuery.TravelMode = TravelMode.Walking;
MyQuery.Waypoints = MyCoordinates;
MyQuery.QueryCompleted += MyQuery_QueryCompleted;
MyQuery.QueryAsync();
}
void MyQuery_QueryCompleted(object sender, QueryCompletedEventArgs<Route> e)
{
if (e.Error == null)
{
Route MyRoute = e.Result;
MapRoute MyMapRoute = new MapRoute(MyRoute);
MyMapRoute.Color = (Colors.Blue);
MyLocMap.AddRoute(MyMapRoute);
#region Draw source location ellipse
Ellipse myCircle = new Ellipse();
myCircle.Fill = new SolidColorBrush(Colors.Blue);
myCircle.Height = 20;
myCircle.Width = 20;
myCircle.Opacity = 50;
MapOverlay myLocationOverlay = new MapOverlay();
myLocationOverlay.Content = myCircle;
myLocationOverlay.PositionOrigin = new Point(0.5, 0.5);
myLocationOverlay.GeoCoordinate = CoordinateConverter.ConvertGeocoordinate(SourceLocation);
MylocationLayer = new MapLayer();
MylocationLayer.Add(myLocationOverlay);
MyLocMap.Layers.Add(MylocationLayer);
#endregion
#region Draw target location ellipse
Ellipse CarCircle = new Ellipse();
CarCircle.Fill = new SolidColorBrush(Colors.Red);
CarCircle.Height = 20;
CarCircle.Width = 20;
CarCircle.Opacity = 50;
MapOverlay CarLocationOverlay = new MapOverlay();
CarLocationOverlay.Content = CarCircle;
CarLocationOverlay.PositionOrigin = new Point(0.5, 0.5);
CarLocationOverlay.GeoCoordinate = CoordinateConverter.ConvertGeocoordinate(TargetLocation);
CarlocationLayer = new MapLayer();
CarlocationLayer.Add(CarLocationOverlay);
MyLocMap.Layers.Add(CarlocationLayer);
#endregion
MyQuery.Dispose();
}
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
SetMapCoordinates();
}
}