var newIcon = new google.maps.MarkerImage('images/red-pushpin.png');
var newIcon = 'http://images/red-pushpin.png';
var newIcon = 'http://maps.google.com/mapfiles/ms/icons/red-pushpin.png';
var MarkerOption = {map:map, position:MarkerLatLng, title:name, icon:newIcon };
var Marker = new google.maps.Marker(MarkerOption);
I am using a VB WebBrowser Control to load an HTML page & access Google Maps via
javascript. It all works, except that I can only access the markers by line 3 above
but I want to use a local image folder (images) but javascrip cant 'see' it, yet
it is in the same directory as the HTML page.
What am I missing, please?
According to the MarkerOptions docs, the icon should be a URL.
So you will only be able to access an image within a url and local files embedded with file:/// tend to be ignored by browsers if the website is being served over http.
So only your 3 line is working.
If in case you want to access your icon image from the local drive, you can do it like this:
var newIcon= "http://mysite.com/images/red-pushpin.png"
In place of mysite replace it with the url that you get for your website when you run it
Related
I am a bit stuck. I have created a script for Photoshop that opens a PSD file containing a few layers plus a linked one, sort of a template.
So far, I got things working for me by creating a droplet that runs the following steps and scripts:
Opening the file/image that is dropped.
Opening the PSD file (opening template, scripted).
Updating all smart objects (including the linked layer, but limited by a specific name and location)(not scripted, recorded action).
Applying the template features to this linked layer which has been updated previously (scripted).
Saves a PNG file (scripted),
And finally, closing up opened image and template documents (recorded action).
All is good so far. But this has a limitation. It will only work on one file at a time, with a specific name, at a specific location. So, for example, for the update linked layer to work, the name of the image must be 1.png inside Downloads folder only, in this case.
So my question is: How can I script this to run an iteration of the update on the linked layer using as source(s) the images dropped onto the droplet, regardless of file types (png, jpg, etc.), name, location, and index the output saved PNG file(s)? (1.png, 2.png, 3.png, and so on.)
I started working on my approach, and the steps previously mentioned:
1 - Opening the file/image that is dropped onto the Photoshop droplet.
This would happen automatically with the file—Photoshop will open the file dropped onto the droplet, thus triggering the specific actions sequence set forth. Step one solved. Next!
2 - Opening the PSD file (opening template, scripted)
With this step, I wrote a script that opens the template file. The first step in the action sequence would be this!
var template = new File("/Users/name/Desktop/Folder/Template.psd"); // Of course, you can have your template file anywhere on your computer as long as the path to find it is correct. I have selected my desktop for testing purposes.
app.open(template);
That was another effortless one. Next!
3 - Updating all smart objects (including the linked layer, but limited by a specific name and location)(not scripted, recorded action)
I needed to ensure that the template would easily find its previously linked layer location for the update for this third step to work. I know there are ways to update this with a script, but I didn't want to tinker with that. It was too much of a hassle for me at this stage and with my limited knowledge. Therefore I've decided to accommodate the necessary so the template would find a familiar file name it would look for when the "Update all Modified Content" action is triggered.
At this stage, there are two files opened in Photoshop, one the initial image that serves as a new source for the template, and the second file the template.psd, which contains the linked layer that needs to be updated with the content of the first file.
First, I have saved a copy of the image using the name that the template would look for when searching for the linked layer's name. Next, I have saved a copy of the template using the location of the first image file to keep the initial template safe from all these actions. And third, I triggered the "Update all Modified Content" action. And voila, everything worked. The initial template had the linked file next to it. So the new template copy would search and find the file next to it, in the same place, folder/location, as it happened on the previews step that helped save it as such.
// The following script will retrieve the path of the opened image and will save a copy that matches the name of the linked layer in the template in the same location.
var image_doc = app.documents[0]; //If two or more documents are opened, this approach will help switch between them.
var image_name = image_doc.name;
var image_path = app.documents[0].path.fsName;
var temp_image = new File("" + image_path + "/" + image_name + "");
var opts, file;
opts = new ExportOptionsSaveForWeb();
opts.format = SaveDocumentType.PNG;
var image_temp_name = "link.png";
pngFile = new File("" + image_path + "/" + image_temp_name + "");
image_doc.exportDocument(pngFile, ExportType.SAVEFORWEB, opts);
// Save a copy of the template.psd in the same location as the image and the link.png file needed to update the linked layer.
var temp_template = new File("" + image_path + "/" + image_name + "");
app.open(template);
var opts, file;
opts = new PhotoshopSaveOptions();
opts.format = SaveDocumentType.PHOTOSHOP;
var template_temp_name = "template.psd";
psdFile = new File(image_path + "/" + template_temp_name);
psdSaveOptions = new PhotoshopSaveOptions();
psdSaveOptions.embedColorProfile = true;
psdSaveOptions.alphaChannels = true;
activeDocument.saveAs(psdFile, psdSaveOptions, false, Extension.LOWERCASE);
// After these Update all Modified Content action
Now, four, five, and six are straightforward:
4 - Applying the template features to this linked layer which has just been updated previously (scripted). Done!
5 - Saves the newly formed template as a PNG file (scripted). Done!
6 - And finally, closing up opened image and template documents (recorded action). Done!
I have a JavaFX application that saves data to a local file data.json which, for example, looks like
data = '[{"name":"Jack","pet":"turtle"},{"name":"John","pet":"black mamba"}]'. Periodically the application adds more entries to this file.
In my html file that I am loading to that application I need to show all this info. I have a script tag that loads that file:
<script type="text/javascript" src="../Data/data.json" id="dataSourceScript"></script>
Then in js code I have var mydata = JSON.parse(data) which allows me to load that JSON into mydata variable as described here.
As I need to update the page content when new entries are added, I have a function I call every couple seconds with setInterval() that does that. In order to get the updated file info, I delete that old <script> tag and add a new one (exactly the same), but this means that data now has the updated info:
var oldScript = document.getElementById("dataSourceScript")
if(oldScript)
oldScript.remove()
var newScript = document.createElement("script")
newScript.setAttribute("id", "dataSourceScript")
newScript.setAttribute("src", "../Data/data.json")
document.body.appendChild(newScript)
var mydata = JSON.parse(data)
//then I just add the new entry to DOM, if there is a new entry
It all works great. If I open my html file in browser and then add a new entry to the file, in a few seconds the page gets updated and shows the new entry too. However, for some reason it does not work in my JavaFX application. It loads the file just once from the initial <script> tag, but if I change data.json file, nothing happens. I have to close the application and reopen it in order to get the new info shown on the page.
(I didn't find any other way to read a file that would work. FileReader just stops reading when a file gets updated, which defeats the purpose; fetch() and XMLHttpRequest() both get blocked by CORS policy; I cannot create a server to request files or install Node or anything else, I need pure html+js to be the UI)
Figured it out thanks to the comments, thanks guys.
Yes, the file I loaded from script tag was being cached and not being updated. A solution is very easy, I just needed to create a variable counter and add it as a version to the new script every time I create it, so it's considered a new one
var version = 0
...
var oldScript = document.getElementById("dataSourceScript")
if(oldScript)
oldScript.remove()
var newScript = document.createElement("script")
newScript.setAttribute("id", "dataSourceScript?version=" + version++)
newScript.setAttribute("src", "../Data/data.json")
document.body.appendChild(newScript)
var mydata = JSON.parse(data)
//then I just add the new entry to DOM, if there is a new entry
My app offers a button to take a screenshot of the current page, which includes a Mapbox map (handled by the nativescript-mapbox plugin). Everything works fine on iOS but on Android, the map is not rendering.
I was pointed from the mapbox team to this example, which addresses their issue with the "regular" Android Graphics Canvas, providing a solution using the Mapbox Snapshot API: https://github.com/mapbox/mapbox-gl-native/blob/master/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/imagegenerator/SnapshotActivity.java#L52
As I am not a Java developer (I barely can handle the {NS} part :) ), I don't know how to convert the code to my pure Javascript {NS} code.
This is what I have now:
var v = view;
var bmp = android.graphics.Bitmap.createBitmap(v.getMeasuredWidth(), v.getMeasuredHeight()+50, android.graphics.Bitmap.Config.ARGB_8888);
v.android.draw(new android.graphics.Canvas(bmp));
var source = new imageSource.ImageSource();
source.setNativeSource(bmp);
//saves image into Documents folder
var folder = fs.knownFolders.documents().path;
var fileName = "Test.png"
var path = fs.path.join(folder, fileName);
var saved = source.saveToFile(path, "png");
Any ideas on how to convert/use their code to capture my entire view, including the map?
Context
I'm trying to download a users' Facebook profile picture to the local storage so that I can display it without having to remake the call to Facebook.
Code
I'm using the module image-source to download the image, and the module file-system to access the device's local storage.
Most of the code is referencing the Nativescript image-source documentation page.
var imageSource = require("image-source");
var fs = require("file-system");
exports.theFunction = function(args){
//...
var img = imageSource.fromFile("http://graph.facebook.com/"+user.id+"/picture?type=large");
var folder = fs.knownFolders.documents();
var path = fs.path.join(folder.path, "profilePic.jpg");
console.log(path);
var saved = img.saveToFile(path, enums.ImageFormat.jpg);
appSettings.setString("imgLocal",path);
console.log("Image Saved Successfully");
//...
}
Output
/data/user/0/com.foo.bar/files/profilePic.jpg
I never see the "Image Saved Successfully" message output to console and I have no way of verifying if the image has been stored in the filesystem using the Emulator (I'm developing for Android without a device).
I have also tried wrapping the save event in an if tag, assuming that the output of saveToFile() is a boolean:
if(img.saveToFile(path, enums.ImageFormat.jpg)) console.log("success");
else console.log("failure");
...however this also outputs nothing.
Question
How can I save the image from the URL to the device's local storage?
References
Nativescript
image-source on Nativescript docs
ImageSource on Nativescript API docs
I think main trouble here is in that line, cause ImageSource works only with local files, not urls:
var img = imageSource.fromFile("http://graph.facebook.com/"+user.id+"/picture?type=large");
You should download image, not set source from url. About downloading image you can read here:
https://docs.nativescript.org/cookbook/ui/image-cache
Or try something like this and save it than somehow:
var image = new ImageModule.Image();
image.src = "https://www.google.com/images/errors/logo_sm_2.png";
But about this I'm not quite sure. I've never used nativescript and just looked through the docs.
I'm working with a website that generates lots of images that I want to save to disk. To do so I need to get a list of URLs containing all the images.
The above picture was taking from the Application tab of Google Chrome's debugging tools. Each of the 'green' files is a 'stored image' or rather, a referenced image URL.
How can I access this list from JavaScript console?
If it is not possible to access this folder/object from javascript, would it be possible to:
Query some database on disk that might contain the files.
Access the files via the Internet Explorer ActiveX Object?
var resources = window.performance.getEntriesByType("resource");
resources.forEach(function (resource) {
console.log(resource.name);
});
The above will list all of the files specified.
var resources = window.performance.getEntriesByType("resource");
resources.forEach(function (resource) {
if (resource.name.indexOf(".png") > -1 || resource.name.indexOf(".jpg")> -1)
console.log(resource.name);
});
As #Sancarn said with my extras line this function will writes all the images that have .png or .jpg as an extension. try it and let me know.