read text file and save the content in an array using JavaScript - javascript

I've searched a lot about this topic, but couldn't find solution. I have a *.txt file containing coordinates (each line has one coordinate) in one column. So, I want to read this file from my file system and use those coordinates to visualize the tracking route on Google Maps API v3. I've already visualized the track for three coordinates and it works fine.
Can anybody just share a sample code of reading a *.txt file and fill an array with the file content? Maybe this is quite easy thing, but I am really stuck on this and would appreciate your help!
Thanks in advance!

You can't read a file using javascript. It's a client-side programming language. But some developpers have developped a solution.
Check this link and tell me if it was helpful for you: http://www.htmlgoodies.com/beyond/javascript/read-text-files-using-the-javascript-filereader.html#fbid=iTAoMveIKhq

I'm not going to share a sample code but you could read the answers to that similar question :
Javascript - read local text file
Basically loading the txt file with Ajax, and read the responseTextattribute of the response.
Although it would be easier to read a xml file or a json file, which would be easier to parse than a simple txt file.

Related

Modify existing excel file with macro using Javascript

I am now working on an Angular application that modifies an existing excel file (.xls) uploaded by the user then save the modified file in the local. The point is this excel file contains some fancy styling and a lot of macros, with several buttons which contains a lot of VBA code (I am not excel expert, sorry if I mistake their name).
I have tried several existing solutions till now:
xlsx
exceljs
For the first solution, I can only access the community version which basically ignores all these information: style, macro/VBA.
For the second solution, it can preserve almost every style but ignores the macro/VBA.
Except for these solutions, I haven't found any working solution. I turn to the community for help, any kind of solution, even a little hint would be appreciated!

Working with PSD on psd.js library

I have a requirement from a client to show images from a PSD(photoshop) file which have multiple layers, on each layer there will be an image, I did some research about it but haven't got any leads, so far I come up with a JS library named psd.js, but I think that is only for parsing and converting to image format(not sure haven't found much documentation on internet). please suggest me if there is any open source library for reading and editing PSD files. (javascript or asp.net preferred)
here is my snippet I have tried so far but haven't got any success, please let me know if there is any way to work with PSDs
thanks.
PSD.fromURL("images/example.psd")
.then(function(psd) {
psd.tree()._children[3]._children[0].visble = false;
document.getElementById('ImageContainer')
.appendChild(psd.image.toPng());
console.log(psd.tree().export());
});
I did something similar for a project of mine, for that you can use imagemagick they even have a command line tool that can make the process very easy. It will let you extract the images from each layer. You can also use psd.js to get information about the each layer positioning and other information.
Hope this helps.

How to use the HTML5 file API to read a pre-specified file?

All the tutorials for the HTML5 file API talk about getting the FileList from a text box. I already have the name of the file (e.g. foo.json), I can't figure out how to read a file given a file name.
This is not for a web app. I'm producing some data in JSON format, and I'd like to format it using Javascript, essentially producing some interactive bar charts. Much in the way that XML can be formatted with XSLT, I want to distribute a JSON file along with some JavaScript code, and when someone clicks the JavaScript file, they have a simple interactive exploration of the data.
So my first problem is to read the JSON file from Javascript. Note that there's no webserver involved.
The short answer is "You can't". It's a security issue; if you find a way please submit a bug report to the browser bug-tracker. Its not even possible to pre-fill the dialog with a filename.
However, for your specific usecase; there doesn't seem to be a need to read a separate file at all. Just include the data as a literal in your JavaScript code.

To deploy those un-readable & nonunderstandable javascript files in a website

Alot of javascript files , hard to understand, and they are necessary. For example
Function(a,b){function d(b){return!a(b).parents().andSelf().filter(function(){return a.curCSS(this,"visibility")==="hidden"||a.expr.filters.hidden(this)}).length}function c(b,c){var e=b.nodeName.toLowerCase();if("area"===e){var f=b.parentNode,g=f.name,h;if(!b.href||!g||f.nodeName.toLowerCase()!=="map")return!1;h=a("img[usemap=#"+g+"]")[0];return!!h&&d(h)}return(/input|select|textarea|button|object/.test(e)?!b.disabled:"a"==e?b.href||c:c)&&d(b)}a.ui=a.ui||{};a.ui.version||(a.extend(a.ui,{version:"1.8.18",keyCode:{ALT:18,BACKSPACE:8,CAPS_LOCK:20,COMMA:188,COMMAND:91,COMMAND_LEFT:91,COMMAND_RIGHT:93,CONTROL:17,DELETE:46,DOWN:40,END:35,ENTER:13,ESCAPE:27,HOME:36,INSERT:45,LEFT:37,MENU:93,NUMPAD_ADD:107,NUMPAD_DECIMAL:110,NUMPAD_DIVIDE:111,NUMPAD_ENTER:108,NUMPAD_MULTIPLY:106,NUMPAD_SUBTRACT:109,PAGE_DOWN:34,PAGE_UP:33,PERIOD:190,RIGHT:39,SHIFT:16,SPACE:32,TAB:9,UP:38,WINDOWS:91}}),a.fn.extend({propAttr:a.fn.prop||a.fn.attr,_focus:a.fn.focus,focus:function(b,c){return typeof b=="number"?this.each(function()
how do guys find out the exact usage of those javascript files downloaded from web somewhere, Jquery website?
So basically , you got a block of codes , downloaded from somewhere and think what it should do and then implement that?
Do you read documents from Jquery website or whatever website you got from to understand how to use that block of codes?
Yes, you read the documentation on the website. This code is minified to make its file size as small as possible so that the time for your users to download is as short as possible. You aren't meant to read it. Optionally, you can often download the unminified source, though documentation is generally more useful than raw source anyway.

Create a search box for my KMLlayer(s)

I'm using Google Maps API v3 and am displaying a basic map with about 250 place markers from a KMZ file. I'd like to add a search box to the page that allows users to search for a specific item in the KML. I'm pretty sure this is possible, but am not sure about the best way to get started... any help pointing me in the right direction would be much appreciated.
Thanks.
As I understand, a KMZ file is a zipped file containing the .KML file and other related files. Reading the KML and extracting values from it is trivial using jquery and you can get information about how to do it here.
http://think2loud.com/224-reading-xml-with-jquery/
I've not done unzipping a file in javascript, but you can check out this StackOverflow question if you want to do everything on the client side.
Unzipping files
Alternately, you can unzip the KMZ file on the server, and let the client code get the KML file using an AJAX get (as shown in the first link).
Hope this helps.

Categories