问题描述:

I have been trying to parse a kml file using the geoxml3 parser. The geoxml3.js file is put in the public folder. The parser is working fine if I put the kml file inside the public folder.

geoXml.parse('doc.kml'); // this is working fine

But how can I make it work if the kml file is located somewhere else, say in the 'uploads' folder outside the public folder. I have tried,

geoXml.parse(uploadPath+'/doc.kml');

but this is not working. How should I specify the file path ? I can't put the kml files in the public folder as any change inside the folder will make the page refresh.

Please help me out.

网友答案:

Haven't tried this one, but Assets.getText() may be what you're looking for. The documentation specifies that you pass it a file path relative to your private directory.

网友答案:

Well, could not resolve the path issue. Assets.getText() is dependent on the private folder and also it doesn't stop the server from restart. But found an alternative solution, where you can upload the file to any folder within your project app and read from it.

// On client side

Meteor.call('getKmlString', kml_file_name, function(error, kml_string) {

        if (error) {
            console.log('ERROR in getting kml string');
            console.log(error);
        } else {
            console.log('GOT Kml String');
            geoXml.parseKmlString(kml_string);
        }

});

// On server side

Meteor.startup(function() {

    // code to run on server at startup
    return Meteor.methods({
        getKmlString: function(kml_file_name) {

            var content = '';

            var fs = Npm.require('fs');
            var encoding = encoding || 'binary';
            var chroot = Meteor.chroot || 'uploads';

            var path = chroot + (path ? '/' + path + '/' : '/');

            var content = fs.readFileSync('../../../../../' + path + kml_file_name, "utf-8", function read(err, data) {

                if (err) {
                    throw err;
                }

            });

            return content;

        },
    });

});
相关阅读:
Top