Serving urls to a Web view controller in Java javafx - google-maps

I'm trying to serve requests to Google API using a JavaFX app. I'm using the Google roads API. Problem is I'm asking user to import an excel document with coordinates and the document can hold as many latitude and longitude data as possible but the Google API only allows less than 100 pairs of coordinates. So how can I serve the data which is in an array list from index at position 0 to 99 and on button press serve the next set of coordinates from 100 to 199 or less. I'm currently able to serve the arraylist.sublist(0to99) and get back a json response. Thanks in advance

//On fx button click the following happens
#FXML public void loadURL(Event event){
co_ordinates = Excel_Exchange.value;
if(!next){
limit = (int)co_ordinates.size();
next = true;//some global boolean variable so that this is done once
}
if(co_ordinates.size()<100){
StringBuilder urlCaseOne = new StringBuilder(co_ordinates.subList(start, co_ordinates.size()).toString().replaceAll("[\\[\\]]","").replaceAll(", ",""));
url_link = "https://roads.googleapis.com/v1/snapToRoads?path="+urlCaseOne.deleteCharAt(urlCaseOne.length()-1)+"&interpolate=true&key="+API_KEY;
}else{
if(limit>100){
StringBuilder urlCaseTwo = new StringBuilder(co_ordinates.subList(start, end).toString().replaceAll("[\\[\\]]","").replaceAll(", ",""));
url_link = "https://roads.googleapis.com/v1/snapToRoads?path="+urlCaseTwo.deleteCharAt(urlCaseTwo.length()-1)+"&interpolate=true&key="+API_KEY;
//System.out.println("l"+limit+" s"+start+" e"+end);
start+=100; end+=100; limit-=100;
}else if(limit<100){
StringBuilder urlCaseThree = new StringBuilder(co_ordinates.subList(start, co_ordinates.size()).toString().replaceAll("[\\[\\]]","").replaceAll(", ",""));
url_link = "https://roads.googleapis.com/v1/snapToRoads?path="+urlCaseThree.deleteCharAt(urlCaseThree.length()-1)+"&interpolate=true&key="+API_KEY;
}
}
//System.out.println(co_ordinates.size());
//System.out.println(url_link);
//System.out.println(co_ordinates.toString().lastIndexOf("|"));
//System.out.println(co_ordinates.subList(0, 99).size());
startLoadState.apply();
this.engine.load(url_link);
}// i have another method that navigates back by to the first url

Related

Embedding MS-Office Documents Into AutoCAD Drawings Using Design Automation

I have a need to embed MS-Office documents (Excel, Word) into AutoCAD using Design Automation. Searching around the web, it seems that this is not possible because the MS-Office applications, which would act as an OLE Client, would need to be running on the Forge Server. Could someone confirm that this is the case?
If I am correct in my above statement, my next best alternative would be to embed .EMF files created from each page of the document I want to embed; alternatively using raster images would also be acceptable. Creating the .EMF or raster files is not a problem. I just can't find a solution for embedding the file that does not involve copying them to the clipboard and using the PASTECLIP command. This approach has worked for me in the AutoCAD application using a C# AutoCAD.NET plugin, an OLE2Frame object is created, but it fails in accoreconsole (because PASTECLIP uses a UI class which is not available). This leads me to think that the same would occur while running the bundle in Design Automation.
The best I have been able achieve so far is to write a raster image files to the working directory and linking the raster images to the AutoCAD document using RasterImageDef and RasterImage (code below). Is this the only way I can do this? Can I do something similar using an EMF image, which is vector based, instead of a raster image? Or is there a way to actually embed an EMF (preferred) or raster image instead of just linking the images?
The code below fails if I use .EMF files, because RasterImageDef and RasterImage do not support the the EMF file; the EMF file being a vector format, not a raster format?
[CommandMethod("TEST")]
public void Test()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
// Get the file name of the image using the editor to prompt for the file name
// Create the prompt
PromptOpenFileOptions options = new PromptOpenFileOptions("Enter Sequence file path");
options.PreferCommandLine = true;
// Get the file name, use no quotes
PromptFileNameResult result = null;
try { result = ed.GetFileNameForOpen(options); }
catch (System.Exception ex)
{
DisplayLogMessage($"Could not get sequence file location. Exception: {ex.Message}.", ed);
return;
}
// Get the rtf filename from the results
string filename = result.StringResult;
DisplayLogMessage($"Got sequence filename: {filename}", ed);
// Load the Sequence.rtf document
Aspose.Words.Document seq;
using (FileStream st = new FileStream(filename, FileMode.Open))
{
seq = new Aspose.Words.Document(st);
st.Close();
}
DisplayLogMessage($"Aspose.Words Loaded: {filename}", ed);
Transaction trans = db.TransactionManager.StartTransaction();
// Get or create the image dictionary
ObjectId imageDictId = RasterImageDef.GetImageDictionary(db);
if (imageDictId != null)
imageDictId = RasterImageDef.CreateImageDictionary(db);
// Open the Image Dictonary
DBDictionary imageDict = (DBDictionary)trans.GetObject(imageDictId, OpenMode.ForRead);
double x = 0.0;
double y = 0.0;
try
{
// For each page in the Sequence.
for (int i = 0; i < seq.PageCount; i++)
{
DisplayLogMessage($"Starting page {i + 1}", ed);
// extract the page.
Aspose.Words.Document newSeq = seq.ExtractPages(i, 1);
Aspose.Words.Saving.ImageSaveOptions imgOptions = new Aspose.Words.Saving.ImageSaveOptions(Aspose.Words.SaveFormat.Emf);
imgOptions.Resolution = 300;
DisplayLogMessage($"Extracted page {i + 1}", ed);
string dictName = Guid.NewGuid().ToString();
filename = Path.Combine(Path.GetDirectoryName(doc.Name), dictName + ".Emf");
// Save the image
SaveOutputParameters sp = newSeq.Save(filename, imgOptions);
DisplayLogMessage($"Saved {dictName}.Emf", ed);
RasterImageDef imageDef = null;
ObjectId imageDefId;
// see if my guid is in there
if (imageDict.Contains(dictName))
imageDefId = (ObjectId)imageDict.GetAt(dictName);
else
{
// Create an image def
imageDef = new RasterImageDef();
imageDef.SourceFileName = $"./{dictName}.Emf";
// load the image
imageDef.Load();
imageDict.UpgradeOpen();
imageDefId = imageDict.SetAt(dictName, imageDef);
trans.AddNewlyCreatedDBObject(imageDef, true);
}
// create raster image to reference the definition
RasterImage image = new RasterImage();
image.ImageDefId = imageDefId;
// Prepare orientation
Vector3d uCorner = new Vector3d(8.5, 0, 0);
Vector3d vOnPlane = new Vector3d(0, 11, 0);
Point3d ptInsert = new Point3d(x, y, 0);
x += 8.5;
CoordinateSystem3d coordinateSystem = new CoordinateSystem3d(ptInsert, uCorner, vOnPlane);
image.Orientation = coordinateSystem;
// some other stuff
image.ImageTransparency = true;
image.ShowImage = true;
// Add the image to ModelSpace
BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);
BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
btr.AppendEntity(image);
trans.AddNewlyCreatedDBObject(image, true);
// Create a reactor between the RasterImage
// and the RasterImageDef to avoid the "Unreferenced"
// warning the XRef palette
RasterImage.EnableReactors(true); // in the original was true
image.AssociateRasterDef(imageDef);
}
trans.Commit();
}
catch (System.Exception ex)
{
DisplayLogMessage("ERROR: " + ex.Message,ed);
trans.Abort();
}
}
Raster images are always linked. There's no way to embed them. The only way to embed an image is to use AcDbOle2Frame (C++) or Autodesk.AutoCAD.DatabaseServices.Ole2Frame (C#). In theory, it is possible to create these objects without the "OLE server" being present but I haven't tried so I don't know if enough APIs are exposed to make it happen.
You should try it and see how far you can get.
Albert
There is way to embed raster image, it is not straightforeward, you need to use C++\ObjectARX API, please refer this https://github.com/MadhukarMoogala/EmbedRasterImage/tree/EmbedRasterImageUsingDBX

Send data changing page Windows Phone

I'm trying to change page and send some data to the new page just create. Basicaly, I have a page where the user could log, I'm gonna save the informations and then I'm going to open a new page by sendind the information to my "profil" page, where the user will have the information about his account. I'm using the MVVM patern, I don't know if it's going to change something but I ad this precision ;).
Edit: The only solution i have found is to pass the string of my object (gladly it is just strings). Because we can pass strings to another page. But I would prefer to give my object directly, or change my architecture if needed. Like don't create a page but replace my Usercontroles by others :(.
Thanks for the help.
For temp data:
If it is WP silverlight app, we can directly assign object to public property of destination page in OnNavigateFrom event of source page. For example, we can declare a public property A on Dest page, and implement the following in Source page to pass the user object:
protected override void OnNavigatedFrom(NavigationEventArgs e)
{
Dest destPage = e.Content as Dest;
if(destPage != null)
{
User a = new User();
a.UserName = "aa";
a.ID = 1;
destPage.A = a;
}
}
For WP runtime app on WP 8.1, you can directly use Frame.Navigate(TypeName, Object) to pass the parameter.
For persist data:
I will suggest storing the data to local storage on source page and read it from destination page.
If I understand right you should use parameters in navigate URI
For example to send name you can use:
NavigationService.Navigate(new Uri("/View/Page.xaml?name=UserName", UriKind.Relative));
and then in OnNavigatedTo() check name parameter:
string name;
NavigationContext.QueryString.TryGetValue("name", out name);
You can use IsolatedStorageSettings.ApplicationSettings["keyname"]=yourobject;
And whenever you want to use this value just unbox this value as below,
if(IsolatedStorageSettings.ApplicationSettings.Contains("keyname"))
{
var obj=(yourobject)IsolatedStorageSettings.ApplicationSettings["keyname"];
}

Uri to open third party apps for wp8

I tried to create an app that opens some third party apps with the help of its Uri from a Tile. Well, it actually works in opening the third party apps but the problem is, first it launches my app(i.e MainPage is visible for a second) and then only it opens the respective app. Is there any way to make my app's MainPage invisible before opening an app or am i missing anything in Capabilities?
Here is my code :
IconicTileData iconicTileData1 = new IconicTileData();
iconicTileData1.Title = name;
iconicTileData1.SmallIconImage = new Uri("/Icons/Small.png", UriKind.Relative);
iconicTileData1.IconImage = new Uri("/Icons/Metro/" + name + "Medium.png", UriKind.Relative);
IconicTileData iconicTileData2 = iconicTileData1;
Uri navigationUri = new Uri("/MainPage.xaml?target=ms-settings-bluetooth:", UriKind.Relative);
ShellTile.Create(navigationUri, (ShellTileData)iconicTileData2, true);
Thanks in advance for your help.
You could try to specify a "custom" page target (instead of MainPage.xaml) and then make a UriMapper that will allow your app to redirect. Here is a nice blog post on creating a UriMapper. Here is some pseudo-code to help:
public class SettingsUriMapper : UriMapperBase
{
public override Uri MapUri(Uri uri)
{
if (uri.OriginalString.StartsWith == "/LaunchSettings.xaml")
{
// parse which settings to go to
// launch settings uri
}
return uri;
}
}

Flickr API image unavailable windows phone

I'm trying to use flicke's api to import images into a Windows Phone app and display them on the phones panoramic dispaly.
I'm new to flickr's API and am stuck ATM.
I've tried the following call:
// original string flickString = "https://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=cc9babb2754c1d29837bea480c97013e&text=game+of+thrones&format=json&nojsoncallback=1&api_sig=bb86a60e9e42f31950bf53d25fc45f08";
string flickString = "https://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=cc9babb2754c1d29837bea480c97013e&text=game+of+thrones&extras=url_sq%2C+url_t%2C+url_s%2C+url_q%2C+url_m%2C+url_n%2C+url_z%2C+url_c%2C+url_l%2C+url_o+&format=json&nojsoncallback=1&api_sig=9e74e094d8c6a7496fc66e070f5c0898";
var baseUrl = string.Format(flickString, flickrAPIKey);
string flickrResult = await client.GetStringAsync(baseUrl);
FlickrData flickrApiData = JsonConvert.DeserializeObject<FlickrData>(flickrResult);
if(flickrApiData.stat == "ok")
{
foreach (Photo data in flickrApiData.photos.photo)
{
// To retrieve one photo
// http://farm{farmid}.staticflickr.com/{server-id}/{id}_{secret}{size}.jpeg
//string photoUrl = "http://farm{0}.staticflickr.com/{1}/{2}_{3}_o.jpeg";
//string photoUrl = "http://farm{0}.staticflickr.com/{1}/{2}_{3}_b.jpeg";
//string photoUrl = "http://farm{0}.staticflickr.com/{1}/{2}_{3}_n.jpg";
string photoUrl = "http://farm{0}.staticflickr.com/{1}/{2}_{3}"
string baseFlickrUrl = string.Format(photoUrl,
data.farm,
data.server,
data.id,
data.secret);
flickr1Image.Source = new BitmapImage(new Uri(baseFlickrUrl));
break;
}
}
}
When I deploy and run the app I get an image saying that this image is unavailiablemessage every time? I've tried changing the search terms etc and still get the sme message. Which is making me wondor if I've missed something setting up my account with flickr earlier that I'm not aware of? It's very frustrating - help please.
Thanks to card_master for his help so far
I'm also integrating with Flickr. I'm creating a web site that uses their api.
I'm using FlickrNet. This is an open source .net library that you can use to call the Flickr Services. This is a C# library.
The benefit of using it on a mobile application you can take advantage of the caching. It allows you to store images in the phones storage. This won't work on a web application though.

Blackberry: Passing KML file to Google Maps

I want to know that can I pass KML as a string to google map application?
Code snippet:
//KML String
String document = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><kml xmlns=\"http://www.opengis.net/kml/2.2\"><Document><Folder><name>Paths</name><open>0</open><Placemark><LineString><tessellate>1</tessellate><coordinates> -112.0814237830345,36.10677870477137,0 -112.0870267752693,36.0905099328766,0</coordinates></LineString></Placemark></Folder></Document></kml>";
//Invoke Google Maps
int module = CodeModuleManager.getModuleHandle("GoogleMaps");
if (module == 0) {
try {
throw new ApplicationManagerException("GoogleMaps isn't installed");
} catch (ApplicationManagerException e) {
System.out.println(e.getMessage());
}
}
String[] args = {document}; //Is this possible???
ApplicationDescriptor descriptor = CodeModuleManager.getApplicationDescriptors(module)[0];
ApplicationDescriptor ad2 = new ApplicationDescriptor(descriptor, args);
try {
ApplicationManager.getApplicationManager().runApplication(ad2, true);
} catch (ApplicationManagerException e) {
System.out.println(e.getMessage());
}
After much R&D...the answer that I found out was that - No, we cannot pass KML as string.
Google Maps Mobile accepts a URL parameter. This needs to be in the form of "http://" and could be either specific parameters (such as "http://gmm/x?....") or a KML file ("http://..../sample.kml").
You MUST parse your mapFile (KML, gpx, txt) IF using the GoogleMaps API.
if all you want is to see your KML file inside a googlemaps window, you can goto the standard http://www.googlemaps.com and inside the ADDRESS box, you put the complete http address of your kml file.
until april2012 this used to work perfectly and the sidebar would be populated correctly, with clickable items (clicking on sidebar entry [e.g. "point 1" would fly-to the equivalent location). as of may2012, this feature is working incorrectly.
IF you want to take things one step further, you can have a PHP page echo the kml (on the fly KML rendering from database or file). BUT, googlemaps will not refresh your dynamically generated output for 10 to 15 minutes.
PM me if you want some javascript GPX and TXT mapFile rendering for GoogleMaps API vs3