Mercurial > hg > STI-GWT
changeset 32:f635bbdc6a03
local KML display (beta)
author | Sebastian Kruse <skruse@mpiwg-berlin.mpg.de> |
---|---|
date | Fri, 30 Nov 2012 15:17:25 +0100 |
parents | c7701b00ca5b |
children | 24c45a9048f2 |
files | src/econnect/wp3_3/client/core/ApplicationGrid.java src/econnect/wp3_3/client/core/StiCore.java war/datasources.json war/scripts/sti/STICore.js |
diffstat | 4 files changed, 72 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/econnect/wp3_3/client/core/ApplicationGrid.java Thu Nov 29 11:33:12 2012 +0100 +++ b/src/econnect/wp3_3/client/core/ApplicationGrid.java Fri Nov 30 15:17:25 2012 +0100 @@ -4,6 +4,7 @@ import java.util.Date; import java.util.List; +import com.google.gwt.user.client.ui.FileUpload; import com.google.gwt.user.client.ui.Grid; import com.google.gwt.user.client.ui.HTML; import com.google.gwt.user.client.ui.HasHorizontalAlignment; @@ -179,6 +180,10 @@ final ListBox datasource = new ListBox(false); final List<ListBox> staticListBoxes = new ArrayList<ListBox>(); final ArrayList<ArrayList<int[]>> entries = new ArrayList<ArrayList<int[]>>(); + final FileUpload uploadKML = new FileUpload(); + //skruse: The element will be accessed by its ID in the JS code + //either don't change this name, or change it also in STICore.js + uploadKML.getElement().setId("localKMLFileChooser"); for( int i=0; i<sources; i++ ){ try { if( core.hasItems(i) ){ @@ -247,10 +252,18 @@ datasource.addChangeHandler(new ChangeHandler() { public void onChange(ChangeEvent event) { int ds = datasource.getSelectedIndex(); + String label = datasource.getItemText(ds); + if( ds == -1 ){ return; } - if( staticListBoxes.get(ds) == null ){ + //skruse: test for local KML loading (e.g. useful for the downloaded KMLs) + //TODO: if this remains in the code, the check below has + //to be improved (some constant somewhere) + if( label.equals("local KML") ){ + openPanel.setWidget(0, 1, uploadKML); + } + else if( staticListBoxes.get(ds) == null ){ openPanel.setWidget(0, 1, searchField); } else { @@ -272,6 +285,8 @@ } private void loadData() { int ds = datasource.getSelectedIndex(); + String label = datasource.getItemText(ds); + if( core.isMaximumReached() ){ core.alert(textConstants.maxDatasources()); } @@ -281,6 +296,13 @@ core.openStaticKml(ds,pair[0],pair[1]); } } + //skruse: test for local KML loading (e.g. useful for the downloaded KMLs) + //TODO: if this remains in the code, the check below has + //to be improved (some constant somewhere) + else if( (label.equals("local KML")) && (uploadKML.getFilename() != "") ){ + String fileName = uploadKML.getFilename(); + core.openLocalKml( ds, fileName ); + } else if( !searchField.getText().equals("") ){ core.openDynamicKml( ds, searchField.getText() ); }
--- a/src/econnect/wp3_3/client/core/StiCore.java Thu Nov 29 11:33:12 2012 +0100 +++ b/src/econnect/wp3_3/client/core/StiCore.java Fri Nov 30 15:17:25 2012 +0100 @@ -421,6 +421,16 @@ }-*/; /** + * Opens a local KML file via HTML5 FileAPI + * + * @param ds the index of the datasource + * @param input the user input text + */ + public final native void openLocalKml(int ds, String fileName) /*-{ + this.retrieveLocalKml( ds, fileName ); + }-*/; + + /** * places a configured time refinement */ public final native void refineByTime(String minTime, String maxTime) /*-{
--- a/war/datasources.json Thu Nov 29 11:33:12 2012 +0100 +++ b/war/datasources.json Fri Nov 30 15:17:25 2012 +0100 @@ -156,5 +156,9 @@ { "label": "Flickr", "url": "/FlickrService/flickr-service?places=false&tags=" + }, + { + "label": "local KML", + "url": "" } ] \ No newline at end of file
--- a/war/scripts/sti/STICore.js Thu Nov 29 11:33:12 2012 +0100 +++ b/war/scripts/sti/STICore.js Fri Nov 30 15:17:25 2012 +0100 @@ -452,6 +452,41 @@ }, /** + * retrieves and loads a kml-file from the local system + * + * @param {int} + * ds the datasource index + * @param {File} + * file the file that the user selected + */ + retrieveLocalKml: function(ds,filename){ + + var core = this; + if( this.blocked ){ + setTimeout( function(){ core.retrieveLocalKml(ds,filename); }, 100 ); + return; + } + core.blockUI(); + + var status = document.getElementById("statusText"); + status.innerHTML = "Retrieving Data ..."; + + var filelist = $('#localKMLFileChooser').get(0).files; + if (filelist.length > 0){ + var file = filelist[0]; + + var reader = new FileReader(); + + reader.readAsText(file); + + status.innerHTML = "Parsing Data ..."; + core.parseIt($.parseXML(reader.result),filename,ds); + } + + return; + }, + + /** * parses the kml-file which includes the results for a given search request * * @param {File}