Hi guys.
Im trying to do single application which is using OpenStreetMaps. I have investigated OpenLayers add-on and used it in my app. Everythink works perfect but, i would like to add few more funcionality. I also added next great add-on LocationTextField, which returns me the longtitude and latitude of the input adress place. Here is my question:
How can i mark the place on map which consider generated longtitude and latitude from the LocationTextField add-on? I figured out that every marked place on map are contained in the PointArray of Vector. The next question is, How to acces into this Vector from the VectorLayer. I saw the method vectorLayer.getSelectedVector(). But im not sure if this is what i need. At this moment i have made a global variable Vector vector; and i have to pass the reference from the Event to this, and then i can add new Point to the PointArray. But i would like to have an access into this without marking first point and getting reference to vector via Event. Next question here is: How to repaint map with new Points? Any ideas would be appreciated. Ima put some code to easier understand what im doing.
Regards bln.
vectorLayer.addListener(new VectorDrawnListener() { //listener which handle marking
public void vectorDrawn(VectorDrawnEvent event) { //Place on the map
vector = event.getVector(); // here i place the reference to this vector.
Point[] atts = vector.getPoints();
lat.setValue(atts[0]
.getLat()); // im showing the latitude and longtitude on the textfields.
lon.setValue(atts[0]
.getLon());
vectorLayer.addVector(vector);
vectorLayer.getWindow().showNotification(
"Vector drawn:" + vector);
}
});
ltf.addListener(new Property.ValueChangeListener() { // listener for LocationTextField
public void valueChange(Property.ValueChangeEvent event) {
GeocodedLocation loc = ltf.getValue();
if (loc != null) {
//System.out.println(loc.get)
lat.setValue("" + loc.getLat());
lon.setValue("" + loc.getLon());
} else {
lat.setValue("");
lon.setValue("");
}
}
});
showPlace.addListener(new Button.ClickListener() { //i would like to show place
@Override // on map after pressing this button
public void buttonClick(Button.ClickEvent event) {
//Vector vector = vectorLayer.getSelectedVector();
if (vector.getPoints() == null) { //if there is no places marked
Double lont = Double.valueOf((String) lon.getValue());
Double lati = Double.valueOf((String) lat.getValue());
Point point = new Point(lont, lati);
Point[] points = {point};
vector.setPoints(points);
vectorLayer.addVector(vector);
} else {
Point[] points = vector.getPoints();
Point[] new_points = new Point[points.length + 1]
;
System.arraycopy(points, 0, new_points, 0, points.length);
Double lont = (Double) lon.getValue(); //longtitude and latitude
Double lati = (Double) lon.getValue(); // im getting from the textfield.
System.out.println(lont+"-"+lati);
Point point = new Point(lont, lati);
new_points[points.length]
= point;
//points[points.length]
= point;
vector.setPoints(points);
vectorLayer.addVector(vector);
// vectorLayer.requestRepaint(); //how to repaint map?
// vectorLayer.requestRepaintAll();
// vectorLayer.requestRepaintRequests();
}
}
});