Dont be complicated if you can be simple.
1) Client-side: pure jQuery and html. JSON + Ajax to communicate with server.
function loadCities() {
var mapbounds = map.getExtent();
mapbounds.transform(toProjection, fromProjection );
bbox = mapbounds.toArray();
var bleft = bbox[0];
var bbottom = bbox[1];
var bright = bbox[2];
var btop = bbox[3];
showLoader();
var origem = "getCities?bleft=" + bleft + "&bbottom=" + bbottom + "&bright=" + bright + "&btop=" + btop;
$.ajax({
url: origem,
dataType: "json"
}).always(function() { hideLoader(); }).done(function(data) {
data = eval( data );
var geojson_format = new OpenLayers.Format.GeoJSON({
'internalProjection': map.baseLayer.projection,
'externalProjection': new OpenLayers.Projection("EPSG:4326")
});
citiesLayer.removeAllFeatures();
citiesLayer.addFeatures(geojson_format.read(data));
});
}
2) Server side: Struts Actions configured to JSON responses:
@Action(value="getCities", results= {
@Result(name="ok", type="httpheader", params={"status", "200"}) }
)
@ParentPackage("default")
public class GetCitiesAction {
public String execute(){
HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(StrutsStatics.HTTP_REQUEST);
Double bleft = Double.parseDouble( request.getParameter("bleft") );
Double bbottom = Double.parseDouble( request.getParameter("bbottom") );
Double bright = Double.parseDouble( request.getParameter("bright") );
Double btop = Double.parseDouble( request.getParameter("btop") );
int idUsuario = Integer.valueOf( request.getParameter("idUsuario") );
String resposta = "";
try {
CityController cc = new CityController( idUsuario );
IStaticElementList lista = cc.getCitiesInBBOX( bleft, bbottom, bright, btop );
resposta = lista.asJson();
} catch ( Exception e ) {
e.printStackTrace();
}
try {
HttpServletResponse response = (HttpServletResponse)ActionContext.getContext().get(StrutsStatics.HTTP_RESPONSE);
response.setCharacterEncoding("UTF-8");
response.getWriter().write(resposta);
} catch (IOException ex) {
ex.printStackTrace();
}
return "ok";
}
}
Hybernate to database access.
Don't forget to keep the domains. See Domain Driven Design.
Mail me if in doubt (see my profile).
Best Answer
It is recommended to use JavaFX for Java desktop applications whenever possible. Here is a good example of Google maps API and JavaFX integration:
https://rterp.wordpress.com/2014/04/25/gmapsfx-add-google-maps-to-your-javafx-application/
This will give you an idea of how you can use it in your own project.
But if you need to embed and display Google Maps in your Java Desktop Swing application, then JxBrowser Java library is what you need. Check this article for example:
http://java.dzone.com/articles/google-maps-java-swing