fetching multiple images from url of xml response in xamarin forms - xamarin.forms

Can anyone guide me how to load images through image_url tags in my image control named BOOK_URL under a loop? i have fetched other book info under similar_books tag of each book tag but unable to fetch images of all book tags in my image control.
My code looks like this.
var xdoc = XDocument.Load("https://www.goodreads.com/book/title.xml?key=Uxb0zPb86N4STVy2ECWYA&title=" + title.Text);
IEnumerable<XElement> allElements =
xdoc.Descendants("similar_books").Descendants("book");
foreach (XElement result in allElements)
{
BOOK_URL.Source = BOOK_URL.Source + "\n"+
ImageSource.FromUri(new Uri(result.Element("image_url").Value)) ;
search.Text = search.Text + "\n" +
" Book Name: " + result.Element("title").Value + "\n" +
" ISBN: " + result.Element("isbn").Value + "\n" +
"Average Ratings: " + result.Element("average_rating").Value + "\n";
}
}
Also my url of xml response look like this:
https://www.goodreads.com/book/title.xml?key=Uxb0zPb86N4STVy2ECWYA&title=DUNE
i am getting all info except for images. Please help me to fetch all images of all book tags as i have fetched other book info rather than images.

this is garbage and should not even compile
BOOK_URL.Source = BOOK_URL.Source + "\n"+
ImageSource.FromUri(new Uri(result.Element("image_url").Value));
assuming that BOOK_URL is an Image control, you want to do
BOOK_URL.Source = ImageSource.FromUri(new Uri(result.Element("image_url").Value));
note that if you have multiple image urls, only the last one in the loop will be assigned
if you have two image controls, you could do this
IEnumerable<XElement> images = xdoc.Descendants("similar_books").
Descendants("book").
Descendants("image_url");
image1.Source = ImageSource.FromUri(new Uri(images[0].Value));
image2.Source = ImageSource.FromUri(new Uri(images[1].Value));

Related

Unable to see 2D text sprites in Autodesk Forge

I'm trying to render 2D text using Sprites in the Autodesk Forge viewer, but I can't get it to show up. If I consult the layer by console I see that it contains the created Sprite but nevertheless I can’t see it in the scene. I have tried different scaling and position settings but no results.
I attach the code below:
function createText(text, preferencia, tamanyo) {
var sprite = spriteTexto("Prueba texto sprite", preferencia, tamanyo);
if (!NOP_VIEWER.impl.overlayScenes['overlaySprites'])
NOP_VIEWER.impl.createOverlayScene('overlaySprites');
NOP_VIEWER.impl.addOverlay('overlaySprites', sprite);
}
function spriteTexto(text, preferencia, tamanyo) {
var fontface = NOP_VIEWER.fontName;
var fontsize = 18; //tamanyo
var borderThickness = 4;
var borderColor = { r:0, g:0, b:0, a:1.0 };
var backgroundColor = { r:0, g:0, b:0, a:0.0 };
var textColor = { r:0, g:0, b:255, a:1 }; //hexadecimalARgb(preferencia.color);
var canvas = document.createElement('canvas');
var context = canvas.getContext('2d');
context.font = "Bold " + fontsize + "px " + fontface;
var metrics = context.measureText( text );
var textWidth = metrics.width;
context.fillStyle = "rgba(" + backgroundColor.r + "," + backgroundColor.g + "," + backgroundColor.b + "," + backgroundColor.a + ")";
context.strokeStyle = "rgba(" + borderColor.r + "," + borderColor.g + "," + borderColor.b + "," + borderColor.a + ")";
context.fillStyle = "rgba(" + textColor.r+", " + textColor.g + ", " + textColor.b + ", 1.0)";
context.fillText( text, borderThickness, fontsize + borderThickness);
var texture = new THREE.Texture(canvas);
texture.needsUpdate = true;
var spriteMaterial = new THREE.SpriteMaterial( { map: texture, useScreenCoordinates: false } );
var sprite = new THREE.Sprite( spriteMaterial );
sprite.scale.set(1*fontsize,1*fontsize,1*fontsize);
sprite.position.set(5,5,6);
return sprite;
}
I would be very grateful if you could help me find the error, thank you very much in advance for your help!
EDIT:------------------------------------------------
We want to render 2D text that can be interacted with (specifically select, rotate, and move).
To do this currently we are working with meshes (using MeshBasicMaterial, Mesh and TextGeometry), but it turns out that the text does not look perfectly sharp, it presents aliasing and we’ve found that according to the API reference, the antialiasing is not applicable to 2d.
Here are some examples of the problem, as you can see, the more we move away from the plane, the worse the text looks (and even up close it doesn't look perfect):
We were trying to make a test representing the text with Sprites (despite the fact that it would mean having to change the entire implementation already made with meshes) to try to implement it in another way that will solve the problem. But we see that it is not possible either.
How can we correct the rendering of the text then? Is there a way to fix it or is this the most we can get in 2D? We've tried searching for information on this but we haven't find anything helpful.
Unfortunately, Forge Viewer doesn't support THREE.Sprite at present. It uses a self-maintained three.js r71 and removes this support as I know.
Could you share the use case in detail on why you want to use THREE.Sprite with Forge Viewer? If you don't want to share that publicly, you can send it to forge (DOT) help (AT) autodesk (DOT) com.

Extract depthmap from Google Street View

Many posts such as this one use the REST API of Google Street View like this:
http://maps.google.com/cbk?output=xml&ll=40.7625000,-73.9741670&dm=1
However, this API does not work sometimes.
Google Street View seems does not rely on that REST API, and it may store the depthmap in this meta-file:
https://www.google.com/maps/photometa/v1?authuser=0&hl=en&gl=us&pb=!1m4!1smaps_sv.tactile!11m2!2m1!1b1!2m2!1sen!2sus!3m3!1m2!1e2!2sG2__WfQLZTzrsr7FP1wUyQ!4m57!1e1!1e2!1e3!1e4!1e5!1e6!1e8!1e12!2m1!1e1!4m1!1i48!5m1!1e1!5m1!1e2!6m1!1e1!6m1!1e2!9m36!1m3!1e2!2b1!3e2!1m3!1e2!2b0!3e3!1m3!1e3!2b1!3e2!1m3!1e3!2b0!3e3!1m3!1e8!2b0!3e3!1m3!1e1!2b0!3e3!1m3!1e4!2b0!3e3!1m3!1e10!2b1!3e2!1m3!1e10!2b0!3e3
But I do not know how to extract depthmap from it. The method using Base64 in this post of Convert depth map (base64) of google street view to image does not work because the encoded string are very different.
Could anyone can get me some ideas? Thanks very much!
Here are some Python code lines to get the meta-file from Google Street View:
def getPanoJS_frm_lonlat(lon, lat):
url = "https://maps.googleapis.com/maps/api/js/GeoPhotoService.SingleImageSearch?pb=!1m5!1sapiv3!5sUS!11m2!1m1!1b0!2m4!1m2!3d{0:}!4d{1:}!2d50!3m10!2m2!1sen!2sGB!9m1!1e2!11m4!1m3!1e2!2b1!3e2!4m10!1e1!1e2!1e3!1e4!1e8!1e6!5m1!1e2!6m1!1e2&callback=_xdc_._v2mub5"
url = url.format(lat, lon)
return requests.get(url, proxies=None)
lon = -74.2249174
lat = 40.7040015
resp = getPanoJS_frm_lonlat(lon, lat)
line = resp.text.replace("/**/_xdc_._v2mub5 && _xdc_._v2mub5( ", "")[:-2]
# print(line)
jdata = json.loads(line)
print("This part may be the depthmap:")
print(jdata[1][5][0][5][3][2])
A part of the encoded depthmap in the metafile(not quite sure, and the entire string is too long to post here, please using the code above the download the meta-file):
Q0RrQUFBSUFBUWdCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUURUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQV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JhbWhzZVVwNFJrNVNaRWRMYjNObFdVNWhVVk4zUXkxblJtTTBhM2hLYjFWTllYSTBjRFJtTmxOUFp6TnhRWEJ4VkRkSVVtaHVZMGN0T1Uxa1ptMXNXR2MzZDB4MVVGSkdVVVpOVEdRNGNIcFZSMWxSUkRoM0FBQUFBQUFBQUlBaWVzbTlzWFVnd1M3QzBUeXpzeHRCa0FHaE84WThtRUVxaENTX0lCRDN3Y1RYV3I3UkthTEJuZElYd0h0MkpzSmVZd0ZBZjM5Q3dzZjhjc0F2dGt2Q2VzV3d2X1dkY01JOTNRVEJsVGxBd2lKNlJzTEk4empDZVpKdHdvcXNPTUtvOXV6QnJzVTV3cDZNaXNMVDR6akNramtmd2h0U09jTFZaR2pDeUJBalF0cUZKOFBhS3pyQ01TM0N3dHp5SlVMUjF0WENmdklsUWl4WE1jT3I4ampDUGVjVXd1djJIMExfMk11OXJYN2dRUXJ6UHNKT2pBRkRES0dUdjRLdm0wTElEWnFfZG5HR1FnbGM1OEgwRUI1Q1BHU2V3WU1aSFVLV0xxSEI0eWdJd3lPakZjTEIwUUZEa2xGZHYzY1ZzRUl1RmtlX1RLRmhRc21tenJ3QjZUUkQxNThDdjdXZ3cwSkc5NEUtZXhUb1F1c1QzVUdUYmdKRGtlMzJRV2gtSDBJUjc2VkJUOFVlUWg3RkZFS3ViUUpERFlzalFvYzJJRUpTUTB0Q1RCd2dRbEhJY2tMV3RSOUNNVktiUVRGcVBNS1dIZVpCb2ZZOXdpQmFRRUowNTBIQ0Jud1pRcDV6UU1MNml0Q18wWWFjd3V6RG5FSTNFd25EZUNZc1FlODhQTUl1dThDX2tFLUt3dTF4RDhETVBzUEM0aGhCd241Z0lrSThfSG9fOTRRMFFwOExKa0ZoZUI1QzE3OTN3T3VORkVMSEQ1akJRZnM2d2c=
I recently came across this problem too and I decided to dig into it with the help of a friend.
I found the GSVPanoDepth.js library that hadn't been updated in a while but still had the fundamentals of decoding the data and parsing it. It was all pretty much the same except the url has changed and the structure of the data a bit too. I forked the repo and updated it to work with the new url and structure - https://github.com/sidequestlegend/GSVPanoDepth.js
// This url no longer works
// url = "http://maps.google.com/cbk?output=json&cb_client=maps_sv&v=4&dm=1&pm=1&ph=1&hl=en&panoid=" + panoId;
url = "https://www.google.com/maps/photometa/v1?authuser=0&hl=en&gl=uk&pb=!1m4!1smaps_sv.tactile!11m2!2m1!1b1!2m2!1sen!2suk!3m3!1m2!1e2!2s" +
panoId +
"!4m57!1e1!1e2!1e3!1e4!1e5!1e6!1e8!1e12!2m1!1e1!4m1!1i48!5m1!1e1!5m1!1e2!6m1!1e1!6m1!1e2!9m36!1m3!1e2!2b1!3e2!1m3!1e2!2b0!3e3!1m3!1e3!2b1!3e2!1m3!1e3!2b0!3e3!1m3!1e8!2b0!3e3!1m3!1e1!2b0!3e3!1m3!1e4!2b0!3e3!1m3!1e10!2b1!3e2!1m3!1e10!2b0!3e3"
fetch(url)
.then(res=>res.text())
.then(res=>JSON.parse(res.substr(4)))
.then(res=>res[1][0][5][0][5][1][2])
.then(res=>{
console.log(res);
return res;
})
.then(dm => {
var decoded, depthMap;
try {
decoded = self.decode(dm);
depthMap = self.parse(decoded);
} catch(e) {
console.error("Error loading depth map for pano " + panoId + "\n" + e.message + "\nAt " + e.filename + "(" + e.lineNumber + ")");
depthMap = self.createEmptyDepthMap();
}
if(self.onDepthLoad) {
self.depthMap = depthMap;
self.onDepthLoad();
}
})
.catch(e=>{
console.error("Request failed: " + url + "\n" + e);
var depthMap = self.createEmptyDepthMap();
if(self.onDepthLoad) {
self.depthMap = depthMap;
self.onDepthLoad();
}
});

Getting image from an online XML file or a URL in xamarin forms

I am unable to get image from a URL that is an XML response. i used following code to fetch information from this URL including image too since i thought that i will get image although the xml response has image url but i am getting image URL instead of image.
Why is it so? kindly guide me! i am a newbie to xamarin forms.
URl : https://www.goodreads.com/book/title.xml?key=Uxb0zPb86N4STVy2ECWYA&title=Dune
CODE:
XElement search_result =(from xFi in Xdoc.Descendants("book")
where (xFi.Element("country_code").Value == "PK") || (xFi.Element("language_code").Value == "eng")
select xFi).FirstOrDefault();
if (search_result != null)
{ search.Text=
"Title: " + search_result.Element("title").Value + "\n" +
"Average Ratings: " + search_result.Element("average_rating").Value + "\n" +
"ISBN: " + search_result.Element("isbn").Value + "\n" +
"PUBLICATION YEAR: " + search_result.Element("publication_year").Value +
"\n" +"PUBLISHER: " + search_result.Element("publisher").Value + "\n" +
"DESCRIPTION: " + "\n" + search_result.Element("description").Value + "\n"
+ "IMAGE: " + "\n" + search_result.Element("image_url").Value + "\n";
} else
{
search.Text = "Found Nothing";
}
assuming I have an Image control on my page named "bookimage"
var url = search_result.Element("image_url").Value;
bookimage.Source = ImageSource.FromUri(new Uri(url));
this is clearly explained in the docs

JSoup - how does HTML structure affect response?

Trying to learn JSoup but having problems with response that may be due to structure issues (or stupidity, you tell me!). I do a simple query for "a[href]" but it only finds a subset 13 (text search tells me there are 162!). Why does it not find all?
Document doc = Jsoup.connect(J_URL).get();
String srchCSS = "a[href]";
Elements select = doc.select(srchCSS);
Iterator<Element> iterator = select.iterator();
Log.w(TAG, "'" + srchCSS + "' # " + select.size());
while (iterator.hasNext()) {
Element x = iterator.next();
System.out.println("'" + srchCSS + "': " + x.text());
}
Log.e(TAG, "%%% COMPLETE %%%");
I want to get the text from 'p' (see RED arrow). The a[href] above it is NOT being found?!?

Inner query in fusion tables

This query will take input from three drop down box and a text box and it work's fine as expected.But my requirement is i need to use another three drop down box and a text in order to query much deeper.So,i need to hold the result of first query and also second query.How should i do.Help me.
That another three drop down box value is also obtained from the same variable's as 'operator','textvalue','querypass'.
function querymap()
{
var operator=document.getElementById('operatorstring').value.replace(/'/g, "\\'");
var textvalue=document.getElementById("text-value").value.replace(/'/g, "\\'");
var querypass=document.getElementById('query-pass').value.replace(/'/g, "\\'");
var searchStringe = document.getElementById('Search-stringe').value.replace(/'/g, "\\'");
var searchString = document.getElementById('search-string').value.replace(/'/g, "\\'");
{
layer.setQuery("SELECT 'geometry'," + querypass + " FROM " + tableid + " WHERE " + querypass + " " + operator + " '" + textvalue + "' AND VillageName = '"+ searchStringe+"'");
}
}
You can have as many AND conditions in your query as you want. No reason not to also check e.g. textvalue2, querypass2, searchString2, etc. and add them to your query. See this setQuery() answer which may give you some ideas. You'll need to set all your search conditions each time you call layer.setQuery() or layer.setOptions({query: ...});

Resources