How to display routes on OpenStreetMaps from richtextbox data, how create list which two value from another array? - arrays

I have this function which get back longitude and latitude from my Rtb data (first picture):
// funkcja pobierająca szerokość i długość geograficzną w formacie dziesiętnym
private Tuple<double, double>[] wsp_geograficzne(string[] lines)
{
return Array.ConvertAll(lines, line =>
{
string[] elems = line.Split(',');
return new Tuple<double, double>(0.01*double.Parse(elems[1]), 0.01*double.Parse(elems[3]));
});
}
This line calls this above function:
var data = wsp_geograficzne(richTextBox1.Lines);
This is a sample, which display routes on my OpenStreetMaps.
GMapOverlay routes = new GMapOverlay(gMapControl1, "routes");// Constructing object for Overlay
gMapControl1.Overlays.Add(routes);
List<PointLatLng> list = new List<PointLatLng>(); // The list of Coordinates to be plotted
list.Add(new PointLatLng(53.119149707703, 23.1447064876556));
list.Add(new PointLatLng(53.11963262556597, 23.1468522548676));
list.Add(new PointLatLng(53.1205276192621, 23.1460046768188));
list.Add(new PointLatLng(53.120701464779, 23.1463050842285));
list.Add(new PointLatLng(53.1200962217943, 23.1489872932434));
list.Add(new PointLatLng(53.1196970143107, 23.1489014625549));
list.Add(new PointLatLng(53.119439459128, 23.1490087509155));
GMapRoute r = new GMapRoute(list, "myroute"); // object for routing
r.Stroke.Width = 5;
r.Stroke.Color = Color.Blue;
routes.Routes.Add(r);
gMapControl1.ZoomAndCenterRoute(r);
gMapControl1.Zoom = 15;
It looks like on the picture:
I want display routes from my data "wsp_geograficzne" (wsp_geograficzne include longitude and latitude) on this map. How should I do it? Is there any method that allow me to create List which data from "wsp_geograficzne"? I trying something like this:
List<PointLatLng> nowa = new List<PointLatLng>();
foreach (var p in data)
nowa.Add(p.Item1, p.Item2);
but it dont works. I get back error: Error 2 No overload for method 'Add' takes 2 arguments.
Please help :)

Ok I find answer (new function which get back 2 value (longitude and latitude) from rtb (longitude and latitude are back in decimal notation):
// funkcja pobierająca szerokość i długość geograficzną w formacie dziesiętnym
private Tuple<double, double>[] wsp_geograficzne(string[] lines)
{
return Array.ConvertAll(lines, line =>
{
string[] elems = line.Split(',');
double we1 = 0.01 * double.Parse(elems[3], EnglishCulture);
int stopnie1 = (int)we1;
double minuty1 = ((we1 - stopnie1) * 100) / 60;
double szerokosc_dziesietna = stopnie1 + minuty1;
double we2 = 0.01 * double.Parse(elems[5], EnglishCulture);
int stopnie2 = (int)we2;
double minuty2 = ((we2 - stopnie2) * 100) / 60;
double dlugosc_dziesietna = stopnie2 + minuty2;
return new Tuple<double, double>(szerokosc_dziesietna, dlugosc_dziesietna);
});
}
And this is a part which display routes on the map.
{
var data = wsp_geograficzne(richTextBox1.Lines);
List<PointLatLng> nowa = new List<PointLatLng>();
foreach (var p in data)
nowa.Add(new PointLatLng(p.Item1, p.Item2));
GMapOverlay routes = new GMapOverlay(gMapControl1, "routes");
gMapControl1.Overlays.Add(routes);
GMapRoute r = new GMapRoute(nowa, "myroute"); // object for routing
r.Stroke.Width = 9;
r.Stroke.Color = Color.Blue;
routes.Routes.Add(r);
gMapControl1.ZoomAndCenterRoute(r);
gMapControl1.Zoom = 16;
}
If someone has another notations this part:
List<PointLatLng> nowa = new List<PointLatLng>();
foreach (var p in data)
nowa.Add(new PointLatLng(p.Item1, p.Item2));
please show me here.
Greetings from Poland :).

Related

Adding a movieclip in each square of my calendar (AS3)

I've got a calendar with squares in wich each date is wrote :
var myArray:Array = new Array();
var row:Number = 0;
var moonNum:Number;
var holder_txt:MovieClip = new MovieClip;
addChild(holder_txt);
holder_txt.x = 35;
holder_txt.y = 10;
startDay -= 1;
for (var t:int = 0; t < getDays(myDate); t++) {
myArray[t] = (t+1);
var textNum:String = myArray[t];
import box;
import moonPhase;
var square:MovieClip = new box();
var moon:MovieClip = new moonPhase();
holder_txt.addChild(square);
square.name = textNum
moonNum= calculateMoonPhase(myDate.fullYear, myDate.month,t+1);
square.texter.text = textNum +" "+ moonNum;
square.x = (startDay) *75
square.y = (row+1)*65
startDay++;
if(startDay >= 7){
startDay = 0;
row++;
I've got a function that calculate the moonPhase for everyday.
moonNum= calculateMoonPhase(myDate.fullYear, myDate.month,t+1);
It results as a number (between 0 and 8).
I've got movieClip of a moon with 8 frames (new moon,full moon...etc).
I'd like to add the movieClip of the moon on each square with the corresponding frame number.
moonClip.gotoAndStop(moonNum);
I've add each moonNum to each square day :
square.texter.text = textNum +" "+ moonNum;
But I've no idea how to add movieclips to each square day...
Any help ?
It's better to add moonPhase in the class box directly. So for each box that you copied, you have an instance of moon in it to.
But, in your sample code, you can add moon to the square directly to.
square.addChild(moon);

MultiList not showing complete text (Codename One)

Im using a MultiList to display some result from a web service but the address is not showing up completely.
Please this picture
The first address should be "Jalan Gertak Merah, 80000 Johor Bahru, Johor, Malaysia" and not "Jalan Gertak Merah, 80"
How can I correct this please.
This is my code:
Style s = UIManager.getInstance().getComponentStyle("Button");
FontImage p = FontImage.createMaterial(FontImage.MATERIAL_PORTRAIT, s);
EncodedImage placeholder = EncodedImage.createFromImage(p.scaled(p.getWidth() * 3, p.getHeight() * 4), false);
f.setTitle("Tourist Attractions");
getattractive();
ArrayList arr = (ArrayList) response.get("results");
for (Object m : arr) {
Map ma = (Map) m;
address = (String) ma.get("formatted_address");
name = (String) ma.get("name");
icon = (String) ma.get("icon");
data.add(createListEntry(name, address, icon));
}
DefaultListModel<Map<String, Object>> model = new DefaultListModel<>(data);
MultiList ml = new MultiList(model);
ml.getUnselectedButton().setIconName("icon_URLImage");
ml.getSelectedButton().setIconName("icon_URLImage");
ml.getUnselectedButton().setIcon(placeholder);
ml.getSelectedButton().setIcon(placeholder);
findContainer(f).add(BorderLayout.CENTER, ml);
c.addComponent(bn);
bn.addActionListener((ActionEvent evt) -> {
System.exit(0);
});
findContainer(f).add(BorderLayout.SOUTH, c);
f.getComponentForm().revalidate();

Can i display multiple copies of a movieclip inside a array at once

Is there a way to make the code below work properly? When I use this code it only shows one movieclip:
var tempHead:head001 = new head001();
var mcArr:Array = new Array( tempHead );
var firstHead:MovieClip = mcArr[0];
firstHead.y = 30;
addChild(firstHead);
var secondHead:MovieClip = mcArr[0];
secondHead.y = 180;
addChild(secondHead);
`
You were just assigning a reference to the MovieClip. That'y, its not working.
First take instance of head001 class using new operator as much you want and store it to an array, then you can access very easily.
var tempHead: head001;
var mcArr: Array = new Array();
for (var i: uint = 0; i < 2; i++) {
tempHead = new head001();
addChild(tempHead);
mcArr.push(tempHead);
mcArr[i].y = mcArr[i].height * i;
}

InvalidCastException: Cannot cast from source type to destination type

I have fetched the data from xml and stored it in an array.I have coded as below
Private var dataarray=new Array();
private var timearray=new Array();
private var distancearray=new Array();
private var detailStock : String;
private var distancedata : String;
private var timedata : String;
private var datalist : String;
private var data : String;
function readMe() {
var filepath : String = Application.dataPath+"/XmlDocs/"+"Stock"+".xml";
var xmlDoc : XmlDocument = new XmlDocument();
if(File.Exists (filepath))
{
xmlDoc.Load( filepath );
var Stock_list : XmlNodeList = xmlDoc.GetElementsByTagName("Stock");
for(var i : int = 0; i < Stock_list.Count;i++)
{
// getting child nodes of stock, like Rice and Wheat in a list
var StockItems_list : XmlNodeList = Stock_list.Item(i).ChildNodes;
// running a loop through all items present in the stock
for(var j : int = 0; j < StockItems_list.Count; j++)
{
//Debug.Log("StockItems_list count"+StockItems_list.Count);
// taking the properties of a item into a list like Price and Quantity
var StockItemsProperties_list : XmlNodeList = StockItems_list.Item(j).ChildNodes;
for(var k : int = 0; k < StockItemsProperties_list.Count; k++)
{
//Debug.Log("length....."+ StockItemsProperties_list[k].InnerText);
data=StockItemsProperties_list[k].InnerText+"\t";
//Debug.Log(data);
/*--------Pushed the full data into an array-----------*/
// dataarray=new Array();
dataarray.Push(data);
//Debug.Log("Elements in the array"+dataarray);
}
//var StockItemsProperties_list : XmlNodeList =StockItems_list[j].
// Getting Names of Items like Rice and Wheat
detailStock+="\n"+StockItems_list[j].Name+"\n";
// We know that Price is stored at Oth element of StockItemsProperties_list
detailStock+=StockItemsProperties_list[0].Name+" ";
// Inner Text of StockItemsProperties_list[0] (Price node) Contains the money
detailStock+=StockItemsProperties_list[0].InnerText+" "+"Rs"+"\n";
// And Quantity at 1st element of StockItemsProperties_list
detailStock+=StockItemsProperties_list[1].Name+" ";
// Inner Text of StockItemsProperties_list[1] (Quantity node) Contains the Quantity in Kg
detailStock+=StockItemsProperties_list[1].InnerText+" "+"Kg"+"\n";
//Debug.Log("distance"+StockItemsProperties_list[0].InnerText);
//Debug.Log("seconds"+StockItemsProperties_list[1].InnerText);
distancedata=StockItemsProperties_list[0].InnerText;
distancearray=new Array();
distancearray.Push(distancedata);
//Debug.Log("distance Array............ "+distancearray);
/*--------------Print the time into time array -----------------*/
timedata=StockItemsProperties_list[1].InnerText;
timearray=new Array();
timearray.Push(timedata);
// Debug.Log("time Array............ "+timearray);
/*-------------Distance and time from both array array ------------------*/
for(var d=0;d<distancearray.length;d++)
{
for(var t=0;t<timearray.length;t++)
{
// Debug.Log("distance : " +distancearray[d] +" "+"time: "+timearray[t]+"\n");
transform.position-=new Vector3(0,distancearray[d],0);
Debug.Log(transform.position);
}
}
With the above code Iam able to print the values.
But I want to move my object based on the values stored in the distancearray. transform.position-=new Vector3(0,distancearray[d],0);
the code for moving an object is getting the below exception
InvalidCastException: Cannot cast from source type to destination type.
Boo.Lang.Runtime.RuntimeServices.CheckNumericPromotion (IConvertible convertible)
Boo.Lang.Runtime.RuntimeServices.CheckNumericPromotion (System.Object value)
Boo.Lang.Runtime.RuntimeServices.UnboxSingle (System.Object value)
xmlDataReader.ReadXml () (at Assets/script/xmlDataReader.js:286)
xmlDataReader.OnGUI () (at Assets/script/xmlDataReader.js:141)
What will be the issue.Any problem with the variable declaration type?.Please help me out
This is UnityScript.
The issue is likely caused by distancedata being String, hence distancearray being array of String, not int.
Try this:
private var distancedata : int;
...
distancedata = parseInt(StockItemsProperties_list[0].InnerText);
Though malformed XML can also be the reason.

Actionscript 3, Flash CC: Placing Objects In An Array From The Library Onto The Stage

Hello programming gurus of stackoverflow, I am hoping that at least one of you will be able to help me with my coding problem. This is the first time I'm posting on this site, so if I miss something with the structure of my post, or anything please let me know (preferably not in a condescending matter) and I will gladly change it.
I actually had a different problem I was going to ask about, but I recently realized that some objects from my library weren't showing up on my stage. Hopefully, if this gets solved I won't have my other problem.
I am creating a learning module app using Flash CC and Actionscript 3, I like to think I am fairly proficient with Flash, but right now all my code is on the timeline because when I started I wasn't aware of the package setup. When I finish with the learning module I'll try and move everything to an AS package, so please bear with me.
This current frame of the module is a drag and drop game where the user drags the correct food, for the animal they chose in the previous frame, to the animal in the middle. The animal is dynamically placed on the stage, as well as an array of six possible food choices, all MovieClips pulled from the library. The array of food elements is actually not what I'm having problem with, they appear on my stage with no problems at all. The problem I'm having is when the user drags the correct food onto the animal, and the win condition is met, the array of balloon elements does not show up on the stage. I find it weird because I'm using near identical code for both the food and balloon array.
Here is my full code:
import flash.display.MovieClip;
import flash.events.MouseEvent;
foodPet();
function foodPet():void {
//all of my pet, food, and balloon library objects have been exported for AS
var theBird:pet_bird = new pet_bird;
var theCat:pet_cat = new pet_cat;
var theChicken:pet_chicken = new pet_chicken;
var theDog:pet_dog = new pet_dog;
var theDuck:pet_duck = new pet_duck;
var theGuinea:pet_guinea = new pet_guinea;
var theHamster:pet_hamster = new pet_hamster;
var birdSeed:food_bird_seed = new food_bird_seed;
var catFood:food_cat_food = new food_cat_food;
var chickenFeed:food_chicken_feed = new food_chicken_feed;
var chocolate:food_chocolate = new food_chocolate;
var dogFood:food_dog_food = new food_dog_food;
var duckFood:food_duck_food = new food_duck_food;
var animalList:Array = [theBird, theCat, theChicken, theDog,
theDuck, theGuinea, theHamster];
var food1Array:Array = [birdSeed, catFood, chickenFeed,
chocolate, dogFood, duckFood, 4];
var xPosFood:Array = new Array();
var yPosFood:Array = new Array();
xPosFood = [32, 71, 146, 363, 431, 512];
yPosFood = [304, 222, 123, 123, 222, 304];
var animalClip:MovieClip;
animalClip = animalList[chosenAnimal];
addChild(animalClip);
animalClip.x = 256;
animalClip.y = 287;
animalClip.name = "selectedAnimal";
for (var i:uint = 0; i < food1Array.length - 1; i++){ //Where the food gets added
var isItRight:Boolean = false;
var foodName:String = ("food" + i);
var foodClip:MovieClip;
foodClip = food1Array[i];
foodClip.x = xPosFood[i];
foodClip.y = yPosFood[i];
foodClip.name = foodName;
addChild(foodClip);
trace(foodClip.parent);
foodDragSetup(foodClip, animalClip, food1Array[food1Array.length - 1], isItRight);
}
}
function foodDragSetup(clip:MovieClip, targ:MovieClip, correctNum:uint, isItRight:Boolean) {
var beingDragged:Boolean = false;
var xPos:Number = clip.x;
var yPos:Number = clip.y;
clip.addEventListener(MouseEvent.MOUSE_DOWN, beginDrag);
function beginDrag(event:MouseEvent):void
{
clip.startDrag();
if (int(clip.name.substr(4)) == correctNum){
isItRight = true;
}
this.beingDragged = true;
setChildIndex(clip, numChildren - 1);
clip.addEventListener(MouseEvent.MOUSE_UP, endDrag);
}
function endDrag(event:MouseEvent):void
{
if (this.beingDragged) {
this.beingDragged = false;
clip.stopDrag();
if ((isItRight) && (clip.hitTestPoint(targ.x, targ.y, true))){
trace(targ.name + " has been hit.");
clip.x = targ.x;
clip.y = targ.y;
win_animal_food();
} else {
isItRight = false;
clip.x = xPos;
clip.y = yPos;
}
}
}
}
function win_animal_food():void {
const BALLOON_ROW:int = 4;
var count:uint = 0;
var altX:uint = 0;
var bBalloon:blue_balloon = new blue_balloon;
var gBalloon:green_balloon = new green_balloon;
var oBalloon:orange_balloon = new orange_balloon;
var pBalloon:purple_balloon = new purple_balloon;
var rBalloon:red_balloon = new red_balloon;
var yBalloon:yellow_balloon = new yellow_balloon;
var balloonList:Array = [bBalloon, gBalloon, oBalloon,
pBalloon, rBalloon, yBalloon, bBalloon, gBalloon,
oBalloon, pBalloon, rBalloon, yBalloon, bBalloon,
gBalloon, oBalloon, pBalloon];
var balloonY:Array = [144, -205, -265, -325];
var balloonX:Array = [0, 140, 284, 428, 68, 212, 356, 500];
for (var ballY:uint = 0; ballY < balloonY.length; ballY++){ //Where balloons
for (var ballX:uint = altX; ballX < altX + BALLOON_ROW; ballX++){ //get added
var balloonName:String = ("balloon" + count);
var balloonClip:MovieClip;
balloonClip = balloonList[count];
balloonClip.x = balloonX[ballX];
balloonClip.y = balloonY[ballY];
balloonClip.name = balloonName;
addChild(balloonClip);
trace(balloonClip.parent);
trace(balloonClip + " has been added!");
balloonClip.addEventListener(MouseEvent.CLICK, balloonPop);
count++;
}
if (altX == 0) {
altX = BALLOON_ROW;
} else {
altX = 0;
}
}
function balloonPop(event:MouseEvent):void {
event.target.play();
event.target.removeEventListener(MouseEvent.CLICK, balloonPop);
}
}
I thought there might have been a problem with my balloon MovieClips, so I subbed them in the food array:
var birdSeed:blue_balloon = new blue_balloon;
var catFood:green_balloon = new green_balloon;
var chickenFeed:orange_balloon = new orange_balloon;
var chocolate:purple_balloon = new purple_balloon;
var dogFood:red_balloon = new red_balloon;
var duckFood:yellow_balloon = new yellow_balloon;
They all showed up on the stage, so there's nothing wrong with the MovieClips.
Added: The first values of balloonXArray and balloonYArray were originally -4 and -145 respectively, but when I started having problems I wanted to make sure the balloons were showing up so I set the first values to 0 and 144 the balloon height and width are both 144 and their cross (not sure on it's name) is in the top left corner.
Added: The reason why there are multiple instances of the same balloon in the balloonList is because I need four rows of four balloons, but only have six different balloons.
I know the balloons are on the stage because the debug display shows their x and y values on the viewable stage. Using trace(foodClip.parent) and trace(balloonClip.parent) shows that the balloons and food all have the same parent, MainTimeline, so I know the balloons aren't getting added to some different space.
I have searched online, but have not come across anyone with a similar problem. Thus, I am asking on this forum if anyone can tell me why my balloons will not show up on the stage.
Please and thank you.
One thing I see straight off in the baloonList is that you have the same object instances listed multiple times. Each instance can only exist on stage exactly once. If you addChild() an instance that is already on stage, the instance is first removed, then re-added at the top of the display list.
You should change:
var bBalloon:blue_balloon = new blue_balloon;
var gBalloon:green_balloon = new green_balloon;
var oBalloon:orange_balloon = new orange_balloon;
var pBalloon:purple_balloon = new purple_balloon;
var rBalloon:red_balloon = new red_balloon;
var yBalloon:yellow_balloon = new yellow_balloon;
var balloonList:Array = [bBalloon, gBalloon, oBalloon,
pBalloon, rBalloon, yBalloon, bBalloon, gBalloon,
oBalloon, pBalloon, rBalloon, yBalloon, bBalloon,
gBalloon, oBalloon, pBalloon];
to:
var balloonList:Array = [
new blue_balloon,
new green_balloon,
new orange_balloon,
new purple_balloon,
new red_balloon,
new yellow_balloon,
new blue_balloon,
new green_balloon,
new orange_balloon,
new purple_balloon,
new red_balloon,
new yellow_balloon,
new blue_balloon,
new blue_balloon,
new green_balloon,
new orange_balloon,
new purple_balloon
];

Resources