How to dynamically create a few pushpin for bing map - windows-phone-7

How can I dynamically create a few pushpin which I need to add them to the bing Map. Say, I need 10 pushpin.
Below is the code.
for( int i =0 ; i <=10 ; i++)
{
Pushpin pp = new Pushpin();
}
--- Update :
Pushpin[] pp = new Pushpin[intcount];
int PinNbr = 1;
//---- get the items out one by one:
foreach (var c in Cat)
{
if (c.GpsLat != null && c.GpsLon != null)
{
//--default fixed location : Lat/Lon
double KM = CalculateDistance("1.xxxxx", "103.xxxxxx", c.GpsLat, c.GpsLon);
if ((KM < 2.0)) )
{
//--- show the pushpin
pp[PinNbr] = new Pushpin();
pp[PinNbr].Content = c.BizId.ToString() + "," + c.BizName;
pp[PinNbr].Width = 180;
pp[PinNbr].Height = 120;
//-------- All use the same eventHandler
pp[PinNbr].MouseLeftButtonUp += new MouseButtonEventHandler(Pushpin_MouseLeftButtonUp);
map1.Children.Add(pp[PinNbr]);
PinNbr++;
}
}
//-- using Lat/lon
map1.Center = new GeoCoordinate(1.2xxxx, 103.3xxx);
map1.ZoomLevel = 13;
}
//-------- All use the same eventHandler

If you are using BingMaps in Windows Phone 7.1, you can do it like this:
for (int i = 0; i <= 10; i++)
{
Pushpin pp = new Pushpin();
pp.Location = new GeoCoordinate(latitude, longitude);
pp.Content = //Content for the Pushpin;
myMap.Children.Add(pp); //myMap is your map control
}

Related

Is it possible to convert an AutoCAD solid3d entity to an Eyeshot brep entity and add it to the Eyeshot model viewport?

I am drawing a Cad Solid3d Entity by changing it to Brep and approaching the face,
but the shape is different. what's wrong
Or is there a way to directly import Autocad solid3d entity into the Eyeshot Model Viewport without redrawing with geometry information?
Below is my code
public void Main()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
CivilDocument cdoc = CivilApplication.ActiveDocument;
using (doc.LockDocument())
{
using (Transaction tr = db.TransactionManager.StartTransaction())
{
List<GBrep.Face> gFaces = new List<GBrep.Face>();
ObjectId solid3dId = EditorInputUtil.GetEntityId(ed, typeof(Solid3d));
GBRepView gBRepView = new GBRepView();
using (Solid3d solid = tr.GetObject(solid3dId, OpenMode.ForWrite) as Solid3d)
using (Brep brep = new Brep(solid))
{
foreach (Face face in brep.Faces)
{
Autodesk.AutoCAD.Geometry.NurbSurface nurbSurface = face.GetSurfaceAsNurb();
int uDegree = nurbSurface.DegreeInU;
int vDegree = nurbSurface.DegreeInV;
KnotCollection uKnotVector = nurbSurface.UKnots;
KnotCollection vKnotVector = nurbSurface.VKnots;
double[] uKnots = ConvertKnotVector(uKnotVector);
double[] vKnots = ConvertKnotVector(vKnotVector);
Point3dCollection p3ts = nurbSurface.ControlPoints;
Point4D[,] controlPoints = ConvertControlPoints(p3ts, nurbSurface.NumControlPointsInU, nurbSurface.NumControlPointsInV);
GSurface gSurface = new GSurface(uDegree, uKnots, vDegree, vKnots, controlPoints);
gBRepView.GetModel.Entities.Add(new devDept.Eyeshot.Entities.Surface(gSurface));
}
}
gBRepView.ShowDialog();
}
}
}
private Point4D[,] ConvertControlPoints(Point3dCollection point3ds, int uNums, int vNums)
{
Point4D[,] controlPoints = new Point4D[uNums, vNums];
int count = 0;
for (int i = 0; i < uNums; i++)
{
for (int j = 0; j < vNums; j++)
{
Point3d cadPoint = point3ds[count];
controlPoints[i, j] = new Point4D(cadPoint.X, cadPoint.Y, cadPoint.Z);
count++;
}
}
return controlPoints;
}

I want to Group questions and answers LINQ and have them display properly

I'm trying to group properly to have my cell distribute eveningly. The printout is coming very odd and uneven.
is it the table i'm creating or group or both? I think the group is correct. My results are as shown in the image below.
Gold is the heading,
Green are the questions,
Red are the answers
Mt table is is below
var Sections = new OncologySection().SelectSections(projectID.ToString());
int iSection = 0;
int igroups = 0;
int ianswer = 0;
tb.CssClass = "";
tb.BorderWidth = 1;
tb.Width = new Unit("780px");
tb.Attributes.Add("runat", "server");
foreach (OncologySection section in Sections)
{
TableRow row1 = new TableRow();
iSection++;
// var getDistinctQuestion = getVoterAnswerstoList.Select(s => s.QuestionText ,s.Id).Distinct().ToList();
var getVoterAnswerstoList = new OncologyGeneratePDFDAL().DataforPDFCreation(Convert.ToInt32(projectID), Convert.ToInt32(voterid), Convert.ToInt32(caseId), Convert.ToInt32(voteSurveyId), Convert.ToInt32(section.SectionID)).OrderBy(os => os.SortOrder);
//var groupedCustomerList = getVoterAnswerstoList
// .GroupBy(u => u.QuestionText, u.QuestionText)
// .Select(grp => grp.ToList())
// .ToList();
var groupedCustomerList = getVoterAnswerstoList.GroupBy(x => new { x.QuestionText, x.DynamicValue }).ToList();
TableCell cell1 = new TableCell();
cell1.BorderWidth = 1;
cell1.Text = section.SectionName;
cell1.BorderColor = System.Drawing.Color.Goldenrod;
cell1.ColumnSpan = groupedCustomerList.Count();
row1.Cells.Add(cell1);
tb.Rows.Add(row1);
TableRow row2 = new TableRow();
foreach (var groups in groupedCustomerList)
{
igroups++;
TableCell cell2 = new TableCell();
var q = (from s in groups select s.QuestionText).FirstOrDefault();
cell2.BorderWidth = 1;
cell2.Text = q;
cell2.BorderColor = System.Drawing.Color.Green;
cell2.ColumnSpan = groupedCustomerList.Count();
row2.Cells.Add(cell2);
if (igroups == groupedCustomerList.Count())
{
tb.Rows.Add(row2);
}
else
{
row2.Cells.Add(cell2);
}
TableRow row3 = new TableRow();
foreach (var answers in groups)
{
ianswer++;
TableCell cell3 = new TableCell();
cell3.BorderWidth = 1;
cell3.BorderColor = System.Drawing.Color.DarkRed;
if (answers.DataTypeId == 7)
{
cell3.Text = answers.DynamicValue.ToString();
}
else if ((answers.DataTypeId == 5) || (answers.DataTypeId == 6) || (answers.DataTypeId == 8))
{
if (answers.VotingValue != 0)
{
cell3.Text = answers.VotingValue.ToString();
}
else
{
cell3.Text = " ";
}
}
else
{
cell3.Text = " ";
}
row3.Cells.Add(cell3);
tb.Rows.Add(row3);
}
}
}
}

How to create an event handler for objects in array?

I'm making a game in which an ellipse is created whenever random number generated is 6. But all of these objects are in an array. Whenever last object of ellipse is created then event handler only works for it and not for previous objects . I've used sender argument to recognize the source but it gives and exception . Here's my code
public static Ellipse[] greenEllipse = new Ellipse[10];
Game.green++;
Game.greenEllipse[green] = new Ellipse();
SolidColorBrush s = new SolidColorBrush();
s.Color = Colors.Green;
SolidColorBrush blackBrush = new SolidColorBrush();
blackBrush.Color = Colors.Black;
// Set Ellipse's width and color
greenEllipse[green].StrokeThickness = 2;
greenEllipse[green].Stroke = blackBrush;
// Fill rectangle with blue color
greenEllipse[green].Fill = s;
greenEllipse[green].Height = 40;
greenEllipse[green].Width = 45;
greenEllipse[green].RenderTransform = new TranslateTransform { X = -200, Y = -72 };
greenEllipse[green].PointerPressed += OnClickge;
g.Children.Add(greenEllipse[green]);
private void OnClickge(object sender, RoutedEventArgs e)
{
var ocg = sender;
tt.Text = nee.ToString();
if (green1 < 4 && nee != 5 && nee != 6)
{
Game.px += nee * 40;
Game.greenEllipse[Convert.ToInt32(ocg)].RenderTransform = new TranslateTransform { X = px, Y = py };
green1 += nee;
}
if (nee == 5)
{
Game.py += (nee) * (-20);
Game.greenEllipse[Convert.ToInt32(ocg)].RenderTransform = new TranslateTransform { X = px + nee, Y = py };
}
if (green1 > 4)
{
if (nee != 5)
{
green1--;
Game.py += nee * (-20);
Game.greenEllipse[Convert.ToInt32(ocg)].RenderTransform = new TranslateTransform { X = px + nee, Y = py };
}
}
}

Memory management in window phone 8

My app need to load image from web each time with provided category and it is working, the problem is memory, Image loaded in memory not being remove when next category image load and hence memory increases and the app closing with the following message-
The program '[4036] TaskHost.exe' has exited with code -2005270523 (0x887a0005).
The code is ---
void webClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error != null)
{
timer.Stop();
return;
}
List rootobj = JsonConvert.DeserializeObject>(e.Result);
int c = 0, x = 0;
for (int i = 0; i < rootobj.Count; i++)
{
Image img = new Image();
img.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
img.VerticalAlignment = System.Windows.VerticalAlignment.Top;
img.Height = 160;
img.Width = 210;
img.Stretch = System.Windows.Media.Stretch.Fill;
BitmapImage bit = new BitmapImage();
string path = rootobj.ElementAt(i).ThumbnailUrl;
bit.UriSource = new Uri(path,UriKind.RelativeOrAbsolute);
img.Source = bit;
img.Margin = new Thickness(x, y, 0, 0);
c++;
if (c == 2)
{
x = 0;
y = y + 160;
c = 0;
}
else
{
x = x + 210;
}
mainGrid.Children.Add(img);
} mainGrid.Children.Add(grid);
}
and to remove i had tried these--
for (int i = 0; i < rootobj.Count; i++)
{
Image image = (Image)mainGrid.Children.ElementAt(i);
BitmapImage bitmapImage = image.Source as BitmapImage;
bitmapImage.UriSource = null;
image.Source = null;
bitmapImage = null;
image = null;
}
grid.Children.Clear();
mainGrid.Children.Remove(grid);
But it still crashes after few type of image selected.
you can do something like the following :
grid1.Children.Remove(image1);
image1 = null;

How to add Dispatcher timer in for loop?

I have to add Dispatcher timer in for loop.I have a multiple pushpin buttons and at run time i wants to retrieve this pushpin buttons in some time interval so how to add dispatcher timer in my loop...
my C# code is....
for (int i = 0; i <= ClsGetDeviceMap.lstLongLatitude.Count - 1; i++)
{
string lat, lon;
lat = ClsGetDeviceMap.lstLatitude.ElementAt<string>(i).Trim();
lon = ClsGetDeviceMap.lstLongLatitude.ElementAt<string>(i).Trim();
Latitude = Convert.ToDouble(lat);
LongLatitude = Convert.ToDouble(lon);
GpsSpeed = 44.21811;
map1.Center = new GeoCoordinate(Latitude, LongLatitude, GpsSpeed);
map1.ZoomLevel = 17;
map1.ZoomBarVisibility = Visibility.Visible;
pin[i] = new Pushpin();
pin[i].Location = new GeoCoordinate(Latitude, LongLatitude);
map1.Children.Add(pin[i]);
myCoorditeWatcher = new GeoCoordinateWatcher(GeoPositionAccuracy.High);
myCoorditeWatcher.MovementThreshold = 20;
//DispatcherTimer newTimer = new DispatcherTimer();
//newTimer.Interval = TimeSpan.FromSeconds(5);
//// newTimer.Tick += map1.Children.Add(pin[i]);
//newTimer.Start();
var gl = GestureService.GetGestureListener(pin[i]);
gl.Hold += new EventHandler<GestureEventArgs>(GestureListener_Hold);
gl.Tap += new EventHandler<GestureEventArgs>(GestureListener_Stack_Tap);
myCoorditeWatcher.PositionChanged += new EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>>(myCoorditeWatcher_PositionChanged);
}
timer = new DispatcherTimer();
timer.Interval = TimeSpan.FromMilliseconds(5000);
timer.Tick += new EventHandler(timer_Tick);
timer.Start();
}
newTimer.Tick += () =>
{
map1.Children.Add(pin[i]);
// probably you need to stop this timer after one tick
//newTimer.Stop();
};

Resources