2

I'm building an application which use this javascript plugin to upload a ZIP file and convert the shapefile in it to GeoJSON, so that it can be added to a map.

My application use ExtJS 6.0 and I can't seem to find how to use the "filefield" button to give the path of the zipped file to the plugin. The problem is that the filefield gives only a fakepath (I think it's for some kind of user-protection). Therefore, I can't use the path given by my form as input for the plugin (I'm getting a 404 error because it use C:\fakepath\file.zip as input). If I give manually the path, everything works fine....

Here's the code of my function:

var getShp = function getShp(){
    Ext.create('Ext.window.Window', {
        title: 'Upload new ESRI shapefile',
        width: 400,
        items: { 
            xtype: 'form',
            id: 'urlFormId',
            items: [{
                xtype: 'filefield',
                name: 'shp',
                fieldLabel: 'Shapefile (*.shp)',
                msgTarget: 'side',
                allowBlank: false,
                anchor: '100%',
                buttonText: 'Select shapefile...'
            }],
            buttons: [{
                text: 'Add layer',
                handler: function() {
                    var form = Ext.getCmp('urlFormId').getForm();
                    var shpUrl = form.findField('shp').getValue();

                    var vectorSource = new ol.source.Vector();

                    loadshp({
                        url: shpUrl,
                        encoding: 'UTF-9',
                        EPSG: '4326'
                    }, function(data) {

                        shpUp = new ol.layer.Vector({
                            name: 'Test world',
                            source: new ol.source.Vector({
                                features: (new ol.format.GeoJSON()).readFeatures(data)
                            })
                        })

                            olMap.addLayer(shpUp);
                    });
                }
            }]
        }
    }).show();
}
kaycee
  • 901
  • 1
  • 9
  • 35
  • You can't get real path, see http://stackoverflow.com/questions/15201071/how-to-get-full-path-of-selected-file-on-change-of-input-type-file-using-jav So your options are either to upload the file to the server and feed that url to the plugin, or read file in javascript and provide its content to the plugin, see http://stackoverflow.com/questions/371875/local-file-access-with-javascript – serg Feb 16 '16 at 23:45

0 Answers0