Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Teemu Auvinen
dtek1066-toinen-ryhmis
Commits
41e65482
Commit
41e65482
authored
Jan 01, 2018
by
Matti Pulkkinen
Browse files
moved URL formation image updating to a separate thread
parent
2ad67daa
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/fi/utu/dtek1066/MapDialog.java
View file @
41e65482
...
...
@@ -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
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment