Commit 41e65482 authored by Matti Pulkkinen's avatar Matti Pulkkinen
Browse files

moved URL formation image updating to a separate thread

parent 2ad67daa
......@@ -33,7 +33,11 @@ public class MapDialog extends JFrame {
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == MapDialog.this.refreshB) {
// try { updateImage(); } catch(Exception ex) { ex.printStackTrace(); }
try {
MapDialog.this.updateImage();
} catch (Exception ex) {
ex.printStackTrace();
}
}
if (e.getSource() == MapDialog.this.leftB) {
// TODO:
......@@ -134,7 +138,7 @@ public class MapDialog extends JFrame {
this.leftPanel.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
this.leftPanel.setMaximumSize(new Dimension(100, 600));
populateLayerList();
this.populateLayerList();
this.leftPanel.add(this.refreshB);
this.leftPanel.add(Box.createVerticalStrut(20));
......@@ -151,25 +155,9 @@ public class MapDialog extends JFrame {
this.setVisible(true);
} // MapDialog()
private void populateLayerList()
throws ParserConfigurationException, SAXException, IOException, MalformedURLException {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder parser = factory.newDocumentBuilder();
Document document = parser.parse(new URL("http://demo.mapserver.org/cgi-bin/"
+ "wms?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetCapabilities").openStream());
Element mapservice = document.getDocumentElement();
NodeList capabilities = mapservice.getElementsByTagName("Layer");
for (int i = 0; i < capabilities.getLength(); i++) {
Element layer = (Element) capabilities.item(i);
String name = layer.getElementsByTagName("Name").item(0).getTextContent();
String title = layer.getElementsByTagName("Title").item(0).getTextContent();
this.leftPanel.add(new LayerCheckBox(name, title, (i == 0) ? true : false));
}
}
// Tarkastetaan mitkä karttakerrokset on valittu,
// tehdään uudesta karttakuvasta pyyntö palvelimelle ja päivitetään kuva
public void updateImage() throws Exception {
public synchronized void updateImage() throws Exception {
String s = "";
// Tutkitaan, mitkä valintalaatikot on valittu, ja
......@@ -187,9 +175,37 @@ public class MapDialog extends JFrame {
s = s.substring(0, s.length() - 1);
}
// TODO:
// getMap-KYSELYN URL-OSOITTEEN MUODOSTAMINEN JA KUVAN PÄIVITYS
// ERILLISESSÄ SÄIKEESSÄ
// imageLabel.setIcon(new ImageIcon(url));
final String ss = s.toString();
new Thread() {
@Override
public void run() {
URL url = null;
try {
url = new URL("http://demo.mapserver.org/cgi-bin/wms?SERVICE="
+ "WMS&VERSION=1.1.1&REQUEST=GetMap&BBOX=-180,-90,180,90&SRS="
+ "EPSG:4326&WIDTH=953&HEIGHT=480&LAYERS=" + ss + "&STYLES="
+ "&FORMAT=image/png&TRANSPARENT=true");
} catch (MalformedURLException e) {
e.printStackTrace();
}
MapDialog.this.imageLabel.setIcon(new ImageIcon(url));
}
}.start();
} // updateImage()
private void populateLayerList()
throws ParserConfigurationException, SAXException, IOException, MalformedURLException {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder parser = factory.newDocumentBuilder();
Document document = parser.parse(new URL("http://demo.mapserver.org/cgi-bin/"
+ "wms?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetCapabilities").openStream());
Element mapservice = document.getDocumentElement();
NodeList capabilities = mapservice.getElementsByTagName("Layer");
for (int i = 0; i < capabilities.getLength(); i++) {
Element layer = (Element) capabilities.item(i);
String name = layer.getElementsByTagName("Name").item(0).getTextContent();
String title = layer.getElementsByTagName("Title").item(0).getTextContent();
this.leftPanel.add(new LayerCheckBox(name, title, (i == 0) ? true : false));
}
}
} // MapDialog
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment