mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-11-06 19:12:23 +00:00
Code reorg, added SimulatorMap to encapusulate the map object.
This commit is contained in:
1 parent
ac4b83254c
commit
0cdfe74fd1
6 files changed
+306
-369
No files matched your search
+7
-5
@@ -131,11 +131,13 @@ public class RaceCourseCanvasOverlay extends FullCanvasOverlay {
|
||||
|
||||
@Override
|
||||
public void onDoubleClick(MapDoubleClickEvent event) {
|
||||
endPoint = event.getLatLng();
|
||||
logger.fine("Clicked endPoint " + "here " + endPoint);
|
||||
if (endPoint != null) {
|
||||
setEndPoint(endPoint);
|
||||
getMap().removeMapMouseMoveHandler(raceCourseMapMouseMoveHandler);
|
||||
if (isSelected) {
|
||||
endPoint = event.getLatLng();
|
||||
logger.fine("Clicked endPoint " + "here " + endPoint);
|
||||
if (endPoint != null) {
|
||||
setEndPoint(endPoint);
|
||||
getMap().removeMapMouseMoveHandler(raceCourseMapMouseMoveHandler);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+9
-204
@@ -1,229 +1,34 @@
|
||||
package com.sap.sailing.gwt.ui.simulator;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.dom.client.Style.Unit;
|
||||
import com.google.gwt.event.dom.client.ClickEvent;
|
||||
import com.google.gwt.event.dom.client.ClickHandler;
|
||||
import com.google.gwt.event.logical.shared.ValueChangeEvent;
|
||||
import com.google.gwt.event.logical.shared.ValueChangeHandler;
|
||||
import com.google.gwt.maps.client.MapWidget;
|
||||
import com.google.gwt.maps.client.Maps;
|
||||
import com.google.gwt.maps.client.geom.LatLng;
|
||||
import com.google.gwt.maps.client.geom.LatLngBounds;
|
||||
import com.google.gwt.maps.client.geom.Point;
|
||||
import com.google.gwt.user.client.Window;
|
||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||
import com.google.gwt.user.client.ui.CheckBox;
|
||||
import com.google.gwt.user.client.ui.DockLayoutPanel;
|
||||
import com.google.gwt.user.client.ui.FlowPanel;
|
||||
import com.google.gwt.user.client.ui.ListBox;
|
||||
import com.google.gwt.user.client.ui.RadioButton;
|
||||
import com.google.gwt.user.client.ui.RootLayoutPanel;
|
||||
import com.google.gwt.user.client.ui.VerticalPanel;
|
||||
import com.sap.sailing.gwt.ui.client.AbstractEntryPoint;
|
||||
import com.sap.sailing.gwt.ui.client.LogoAndTitlePanel;
|
||||
import com.sap.sailing.gwt.ui.client.SimulatorService;
|
||||
import com.sap.sailing.gwt.ui.client.SimulatorServiceAsync;
|
||||
import com.sap.sailing.gwt.ui.shared.PositionDTO;
|
||||
import com.sap.sailing.gwt.ui.shared.WindFieldDTO;
|
||||
import com.sap.sailing.gwt.ui.shared.WindFieldGenParamsDTO;
|
||||
import java.util.logging.*;
|
||||
|
||||
|
||||
public class SimulatorEntryPoint extends AbstractEntryPoint {
|
||||
private final SimulatorServiceAsync simulatorSvc = GWT.create(SimulatorService.class);
|
||||
|
||||
// private final VerticalPanel panel = new VerticalPanel();
|
||||
private final DockLayoutPanel panel = new DockLayoutPanel(Unit.PX);
|
||||
private final ListBox raceSelector = new ListBox();
|
||||
private final CheckBox checkBox = new CheckBox("Show Grid");
|
||||
private RadioButton windDisplayButton;
|
||||
private RadioButton courseInputButton;
|
||||
private RadioButton summaryButton;
|
||||
private RadioButton replayButton;
|
||||
private MapWidget mapw;
|
||||
|
||||
private List<PositionDTO> locations = new ArrayList<PositionDTO>();
|
||||
|
||||
private static Logger logger = Logger.getLogger("com.sap.sailing");
|
||||
|
||||
|
||||
@Override
|
||||
public void onModuleLoad() {
|
||||
super.onModuleLoad();
|
||||
|
||||
/*
|
||||
* Asynchronously loads the Maps API.
|
||||
*
|
||||
* The first parameter should be a valid Maps API Key to deploy this application on a public server, but a blank
|
||||
* key will work for an application served from localhost.
|
||||
*/
|
||||
Maps.loadMapsApi("", "2", false, new Runnable() {
|
||||
public void run() {
|
||||
// buildUi();
|
||||
createUi();
|
||||
}
|
||||
});
|
||||
createUi();
|
||||
}
|
||||
|
||||
private void createUi() {
|
||||
initMap();
|
||||
//initMap();
|
||||
|
||||
SimulatorMainPanel mainPanel = new SimulatorMainPanel(mapw, stringMessages, simulatorSvc);
|
||||
SimulatorMainPanel mainPanel = new SimulatorMainPanel(simulatorSvc,stringMessages);
|
||||
RootLayoutPanel.get().add(mainPanel);
|
||||
}
|
||||
|
||||
private void buildUi() {
|
||||
logger.severe("Logger Name : " + logger.getName() + " Logging level " + logger.getLevel());
|
||||
logger.fine("In buildUi");
|
||||
loadRaceLocations();
|
||||
|
||||
|
||||
initMap();
|
||||
initRaceSelector();
|
||||
initDisplayOptions();
|
||||
// initButton();
|
||||
initPanel();
|
||||
|
||||
// Add the map to the HTML host page
|
||||
RootLayoutPanel.get().add(panel);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void initMap() {
|
||||
logger.fine("In initMap");
|
||||
mapw = new MapWidget();
|
||||
mapw.setUI(SimulatorMapOptions.newInstance());
|
||||
mapw.setZoomLevel(15);
|
||||
mapw.setSize("100%", "650px");
|
||||
// mapw.setSize("100%", "80%");
|
||||
PositionDTO kiel = new PositionDTO(54.33194056834371, 10.155057907104492);
|
||||
|
||||
LatLng position = LatLng.newInstance(kiel.latDeg, kiel.lngDeg);
|
||||
mapw.panTo(position);
|
||||
}
|
||||
|
||||
private void loadRaceLocations() {
|
||||
logger.fine("In loadRaceLocations");
|
||||
simulatorSvc.getRaceLocations(new AsyncCallback<PositionDTO[]>() {
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
String message = caught.getMessage();
|
||||
for (StackTraceElement ste : caught.getStackTrace()) {
|
||||
message += ste.toString() + "\n\t";
|
||||
}
|
||||
Window.alert("Failed servlet call to SimulatorService\n" + message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(PositionDTO[] result) {
|
||||
locations.clear();
|
||||
int i = 0;
|
||||
for (PositionDTO rl : result) {
|
||||
locations.add(rl);
|
||||
raceSelector.addItem(Integer.toString(++i));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void initRaceSelector() {
|
||||
logger.fine("In initRaceSelector");
|
||||
raceSelector.setVisibleItemCount(1);
|
||||
raceSelector.setTitle("Race Location Selection");
|
||||
raceSelector.setSize("100%", "20px");
|
||||
|
||||
raceSelector.addClickHandler(new ClickHandler() {
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
PositionDTO rl = locations.get(raceSelector.getSelectedIndex());
|
||||
selectRaceLocation(rl);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void initPanel() {
|
||||
logger.fine("In initPanel");
|
||||
|
||||
LogoAndTitlePanel logoAndTitlePanel = new LogoAndTitlePanel("Simulator", stringMessages);
|
||||
logoAndTitlePanel.addStyleName("LogoAndTitlePanel");
|
||||
panel.addNorth(logoAndTitlePanel, 68);
|
||||
|
||||
FlowPanel controlPanel = new FlowPanel();
|
||||
controlPanel.add(raceSelector);
|
||||
panel.addWest(controlPanel, 200);
|
||||
|
||||
VerticalPanel mapDisplayPanel = new VerticalPanel();
|
||||
mapDisplayPanel.add(courseInputButton);
|
||||
mapDisplayPanel.add(windDisplayButton);
|
||||
mapDisplayPanel.add(summaryButton);
|
||||
mapDisplayPanel.add(replayButton);
|
||||
courseInputButton.setChecked(true);
|
||||
panel.addEast(mapDisplayPanel, 200);
|
||||
|
||||
// panel.addWest(checkBox,200);
|
||||
panel.add(mapw);
|
||||
|
||||
// TabPanel tabPanel = new TabPanel();
|
||||
// FlowPanel flowPanel = new FlowPanel();
|
||||
// flowPanel.add(mapw);
|
||||
/*
|
||||
* tabPanel.add(flowPanel, "Summary"); flowPanel = new FlowPanel(); flowPanel.add(mapw); tabPanel.add(flowPanel,
|
||||
* "Replay"); flowPanel = new FlowPanel(); flowPanel.add(mapw); tabPanel.add(flowPanel, "Wind Display");
|
||||
* tabPanel.selectTab(0); tabPanel.addStyleName("table-center"); tabPanel.setSize("100%","100%");
|
||||
*/
|
||||
// panel.add(tabPanel);
|
||||
// panel.add(flowPanel);
|
||||
|
||||
panel.setSize("100%", "100%");
|
||||
}
|
||||
|
||||
private void selectRaceLocation(PositionDTO rl) {
|
||||
logger.fine("In selectRaceLocation");
|
||||
// mapw.clearOverlays();
|
||||
LatLng position = LatLng.newInstance(rl.latDeg, rl.lngDeg);
|
||||
mapw.panTo(position);
|
||||
}
|
||||
|
||||
private void initDisplayOptions() {
|
||||
logger.fine("In initDisplayOptions");
|
||||
checkBox.setSize("100%", "20px");
|
||||
checkBox.setTitle("Grid Selector");
|
||||
checkBox.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
|
||||
|
||||
@Override
|
||||
public void onValueChange(ValueChangeEvent<Boolean> event) {
|
||||
// generateWindField();
|
||||
}
|
||||
});
|
||||
/*
|
||||
* if (checkBox.length > 1) { checkBox[0].setText("Grid"); checkBox[1].setText("Wind Direction"); }
|
||||
*/
|
||||
}
|
||||
|
||||
/*
|
||||
* private void initButton() { windDisplayButton = new RadioButton("Map Display Options", "Wind Display");
|
||||
* windDisplayButton.addClickHandler( new ClickHandler() {
|
||||
*
|
||||
* @Override public void onClick(ClickEvent arg0) {
|
||||
*
|
||||
* if (raceCourseCanvasOverlay.isCourseSet()) { mapw.addOverlay(windFieldCanvasOverlay); generateWindField();
|
||||
* raceCourseCanvasOverlay.setVisible(true); } else {
|
||||
* Window.alert("No course set, please initialize the course with Start-End Input"); } } });
|
||||
*
|
||||
* courseInputButton = new RadioButton("Map Display Options","Start End Input");
|
||||
* courseInputButton.addClickHandler(new ClickHandler() {
|
||||
*
|
||||
* @Override public void onClick(ClickEvent arg0) {
|
||||
*
|
||||
* mapw.removeOverlay(windFieldCanvasOverlay);
|
||||
*
|
||||
* //raceCourseCanvasOverlay.setSelected(true); //raceCourseCanvasOverlay.setVisible(true);
|
||||
* raceCourseCanvasOverlay.reset(); raceCourseCanvasOverlay.redraw(true);
|
||||
*
|
||||
* } });
|
||||
*
|
||||
* replayButton = new RadioButton("Map Display Options","Replay"); summaryButton = new
|
||||
* RadioButton("Map Display Options","Summary"); }
|
||||
*/
|
||||
|
||||
}
|
||||
+34
-158
@@ -34,40 +34,34 @@ public class SimulatorMainPanel extends SplitLayoutPanel {
|
||||
private FlowPanel leftPanel = new FlowPanel();
|
||||
private FlowPanel rightPanel = new FlowPanel();
|
||||
|
||||
Button updateButton;
|
||||
Button courseInputButton;
|
||||
private Button updateButton;
|
||||
private Button courseInputButton;
|
||||
|
||||
RadioButton summaryButton;
|
||||
RadioButton replayButton;
|
||||
RadioButton windDisplayButton;
|
||||
private RadioButton summaryButton;
|
||||
private RadioButton replayButton;
|
||||
private RadioButton windDisplayButton;
|
||||
|
||||
private WindFieldCanvasOverlay windFieldCanvasOverlay;
|
||||
private PathCanvasOverlay pathCanvasOverlay;
|
||||
private RaceCourseCanvasOverlay raceCourseCanvasOverlay;
|
||||
|
||||
private final StringMessages stringMessages;
|
||||
private MapWidget mapw;
|
||||
private SimulatorServiceAsync simulatorSvc;
|
||||
private WindControlParameters wControls = new WindControlParameters();
|
||||
|
||||
private ListBox patternSelector = new ListBox();
|
||||
private ListBox boatSelector = new ListBox();
|
||||
|
||||
WindFieldGenParamsDTO windParams = new WindFieldGenParamsDTO();
|
||||
|
||||
private static Logger logger = Logger.getLogger("com.sap.sailing");
|
||||
|
||||
/**
|
||||
* Temporary place holders for parameters
|
||||
*/
|
||||
private final int xRes = 5;
|
||||
private final int yRes = 5;
|
||||
private final double windSpeed = 7.2;
|
||||
private final double windBearing = 45;
|
||||
|
||||
public SimulatorMainPanel(MapWidget mapw, StringMessages stringMessages, SimulatorServiceAsync svc) {
|
||||
private SimulatorMap simulatorMap;
|
||||
private final StringMessages stringMessages;
|
||||
private final SimulatorServiceAsync simulatorSvc;
|
||||
|
||||
public SimulatorMainPanel(SimulatorServiceAsync svc, StringMessages stringMessages) {
|
||||
// splitPanel = new SplitLayoutPanel();
|
||||
super();
|
||||
this.mapw = mapw;
|
||||
|
||||
this.stringMessages = stringMessages;
|
||||
this.simulatorSvc = svc;
|
||||
|
||||
@@ -85,8 +79,7 @@ public class SimulatorMainPanel extends SplitLayoutPanel {
|
||||
rightPanel.getElement().getStyle().setBackgroundColor("#e0e0e0");
|
||||
this.add(rightPanel);
|
||||
// rightPanel.getElement().getStyle().setFloat(Style.Float.RIGHT);
|
||||
addOverlays();
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void createOptionsPanelTop() {
|
||||
@@ -186,92 +179,17 @@ public class SimulatorMainPanel extends SplitLayoutPanel {
|
||||
rightPanel.add(mapOptions);
|
||||
|
||||
initDisplayOptions(mapOptions);
|
||||
|
||||
FlowPanel mapPanel = new FlowPanel();
|
||||
mapPanel.setTitle("Map");
|
||||
|
||||
mapPanel.add(mapw);
|
||||
// mapPanel.setSize("100%", "80%");
|
||||
rightPanel.add(mapPanel);
|
||||
}
|
||||
|
||||
private void addOverlays() {
|
||||
raceCourseCanvasOverlay = new RaceCourseCanvasOverlay();
|
||||
mapw.addOverlay(raceCourseCanvasOverlay);
|
||||
|
||||
windFieldCanvasOverlay = new WindFieldCanvasOverlay();
|
||||
// mapw.addOverlay(windFieldCanvasOverlay);
|
||||
pathCanvasOverlay = new PathCanvasOverlay();
|
||||
}
|
||||
|
||||
private void generateWindField() {
|
||||
logger.info("In generateWindField");
|
||||
|
||||
PositionDTO startPointDTO = new PositionDTO(raceCourseCanvasOverlay.startPoint.getLatitude(),
|
||||
raceCourseCanvasOverlay.startPoint.getLongitude());
|
||||
PositionDTO endPointDTO = new PositionDTO(raceCourseCanvasOverlay.endPoint.getLatitude(),
|
||||
raceCourseCanvasOverlay.endPoint.getLongitude());
|
||||
logger.info("StartPoint:" + startPointDTO);
|
||||
windParams.setNorthWest(startPointDTO);
|
||||
windParams.setSouthEast(endPointDTO);
|
||||
windParams.setxRes(xRes);
|
||||
windParams.setyRes(yRes);
|
||||
windParams.setWindBearing(windBearing);
|
||||
windParams.setWindSpeed(windSpeed);
|
||||
|
||||
simulatorSvc.getWindField(windParams, new AsyncCallback<WindFieldDTO>() {
|
||||
@Override
|
||||
public void onFailure(Throwable message) {
|
||||
Window.alert("Failed servlet call to SimulatorService\n" + message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(WindFieldDTO wl) {
|
||||
logger.info("Number of windDTO : " + wl.getMatrix().size());
|
||||
refreshWindFieldOverlay(wl);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void refreshWindFieldOverlay(WindFieldDTO wl) {
|
||||
windFieldCanvasOverlay.setWindField(wl);
|
||||
windFieldCanvasOverlay.redraw(true);
|
||||
}
|
||||
|
||||
private void generatePath() {
|
||||
logger.info("In generatePath");
|
||||
|
||||
PositionDTO startPointDTO = new PositionDTO(raceCourseCanvasOverlay.startPoint.getLatitude(),
|
||||
raceCourseCanvasOverlay.startPoint.getLongitude());
|
||||
PositionDTO endPointDTO = new PositionDTO(raceCourseCanvasOverlay.endPoint.getLatitude(),
|
||||
raceCourseCanvasOverlay.endPoint.getLongitude());
|
||||
|
||||
windParams.setNorthWest(startPointDTO);
|
||||
windParams.setSouthEast(endPointDTO);
|
||||
windParams.setxRes(xRes);
|
||||
windParams.setyRes(yRes);
|
||||
windParams.setWindBearing(windBearing);
|
||||
windParams.setWindSpeed(windSpeed);
|
||||
|
||||
simulatorSvc.getPaths(windParams, new AsyncCallback<PathDTO[]>() {
|
||||
@Override
|
||||
public void onFailure(Throwable message) {
|
||||
Window.alert("Failed servlet call to SimulatorService\n" + message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(PathDTO[] paths) {
|
||||
logger.info("Number of Paths : " + paths.length);
|
||||
/* TODO Revisit for now creating a WindFieldDTO from the path */
|
||||
WindFieldDTO pathWindDTO = new WindFieldDTO();
|
||||
pathWindDTO.setMatrix(paths[0].getMatrix());
|
||||
pathCanvasOverlay.setWindField(pathWindDTO);
|
||||
pathCanvasOverlay.redraw(true);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
simulatorMap = new SimulatorMap(simulatorSvc, stringMessages);
|
||||
|
||||
//FlowPanel mapPanel = new FlowPanel();
|
||||
//mapPanel.setTitle("Map");
|
||||
//mapPanel.setSize("100%", "92%");
|
||||
//mapPanel.add(mapw);
|
||||
//mapw.setSize("100%", "100%");
|
||||
|
||||
simulatorMap.setSize("100%", "92%");
|
||||
rightPanel.add(simulatorMap);
|
||||
}
|
||||
|
||||
private void initUpdateButton() {
|
||||
@@ -281,16 +199,12 @@ public class SimulatorMainPanel extends SplitLayoutPanel {
|
||||
@Override
|
||||
public void onClick(ClickEvent arg0) {
|
||||
|
||||
if (raceCourseCanvasOverlay.isCourseSet()) {
|
||||
if (windDisplayButton.getValue()) {
|
||||
refreshWindDisplayView();
|
||||
} else if (summaryButton.getValue()) {
|
||||
refreshSummaryView();
|
||||
} else if (replayButton.getValue()) {
|
||||
refreshReplayView();
|
||||
}
|
||||
} else {
|
||||
Window.alert("No course set, please initialize the course with Start-End Input");
|
||||
if (windDisplayButton.getValue()) {
|
||||
simulatorMap.refreshView(SimulatorMap.ViewName.WINDDISPLAY, wControls);
|
||||
} else if (summaryButton.getValue()) {
|
||||
simulatorMap.refreshView(SimulatorMap.ViewName.SUMMARY, wControls);
|
||||
} else if (replayButton.getValue()) {
|
||||
simulatorMap.refreshView(SimulatorMap.ViewName.REPLAY, wControls);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -304,13 +218,7 @@ public class SimulatorMainPanel extends SplitLayoutPanel {
|
||||
courseInputButton.addClickHandler(new ClickHandler() {
|
||||
@Override
|
||||
public void onClick(ClickEvent arg0) {
|
||||
|
||||
mapw.removeOverlay(windFieldCanvasOverlay);
|
||||
mapw.removeOverlay(pathCanvasOverlay);
|
||||
// raceCourseCanvasOverlay.setSelected(true);
|
||||
// raceCourseCanvasOverlay.setVisible(true);
|
||||
raceCourseCanvasOverlay.reset();
|
||||
raceCourseCanvasOverlay.redraw(true);
|
||||
simulatorMap.reset();
|
||||
|
||||
}
|
||||
});
|
||||
@@ -324,11 +232,7 @@ public class SimulatorMainPanel extends SplitLayoutPanel {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent arg0) {
|
||||
if (raceCourseCanvasOverlay.isCourseSet()) {
|
||||
refreshSummaryView();
|
||||
} else {
|
||||
Window.alert("No course set, please initialize the course with Start-End Input");
|
||||
}
|
||||
simulatorMap.refreshView(SimulatorMap.ViewName.SUMMARY, wControls);
|
||||
}
|
||||
|
||||
});
|
||||
@@ -339,11 +243,7 @@ public class SimulatorMainPanel extends SplitLayoutPanel {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent arg0) {
|
||||
if (raceCourseCanvasOverlay.isCourseSet()) {
|
||||
refreshReplayView();
|
||||
} else {
|
||||
Window.alert("No course set, please initialize the course with Start-End Input");
|
||||
}
|
||||
simulatorMap.refreshView(SimulatorMap.ViewName.REPLAY, wControls);
|
||||
}
|
||||
|
||||
});
|
||||
@@ -355,11 +255,7 @@ public class SimulatorMainPanel extends SplitLayoutPanel {
|
||||
@Override
|
||||
public void onClick(ClickEvent arg0) {
|
||||
|
||||
if (raceCourseCanvasOverlay.isCourseSet()) {
|
||||
refreshWindDisplayView();
|
||||
} else {
|
||||
Window.alert("No course set, please initialize the course with Start-End Input");
|
||||
}
|
||||
simulatorMap.refreshView(SimulatorMap.ViewName.WINDDISPLAY, wControls);
|
||||
}
|
||||
|
||||
});
|
||||
@@ -376,24 +272,4 @@ public class SimulatorMainPanel extends SplitLayoutPanel {
|
||||
|
||||
}
|
||||
|
||||
private void refreshSummaryView() {
|
||||
mapw.removeOverlay(windFieldCanvasOverlay);
|
||||
pathCanvasOverlay.displayWindAlongPath = true;
|
||||
mapw.addOverlay(pathCanvasOverlay);
|
||||
generatePath();
|
||||
}
|
||||
|
||||
private void refreshReplayView() {
|
||||
mapw.addOverlay(windFieldCanvasOverlay);
|
||||
pathCanvasOverlay.displayWindAlongPath = false;
|
||||
mapw.addOverlay(pathCanvasOverlay);
|
||||
generateWindField();
|
||||
generatePath();
|
||||
}
|
||||
|
||||
private void refreshWindDisplayView() {
|
||||
mapw.removeOverlay(pathCanvasOverlay);
|
||||
mapw.addOverlay(windFieldCanvasOverlay);
|
||||
generateWindField();
|
||||
}
|
||||
}
|
||||
+243
@@ -0,0 +1,243 @@
|
||||
package com.sap.sailing.gwt.ui.simulator;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.google.gwt.maps.client.MapWidget;
|
||||
import com.google.gwt.maps.client.Maps;
|
||||
import com.google.gwt.maps.client.control.ControlAnchor;
|
||||
import com.google.gwt.maps.client.control.ControlPosition;
|
||||
import com.google.gwt.maps.client.control.LargeMapControl3D;
|
||||
import com.google.gwt.maps.client.control.MenuMapTypeControl;
|
||||
import com.google.gwt.maps.client.control.ScaleControl;
|
||||
import com.google.gwt.maps.client.geom.LatLng;
|
||||
import com.google.gwt.user.client.Window;
|
||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||
import com.google.gwt.user.client.ui.AbsolutePanel;
|
||||
import com.sap.sailing.gwt.ui.client.RequiresDataInitialization;
|
||||
import com.sap.sailing.gwt.ui.client.SimulatorServiceAsync;
|
||||
import com.sap.sailing.gwt.ui.client.StringMessages;
|
||||
import com.sap.sailing.gwt.ui.shared.PathDTO;
|
||||
import com.sap.sailing.gwt.ui.shared.PositionDTO;
|
||||
import com.sap.sailing.gwt.ui.shared.WindFieldDTO;
|
||||
import com.sap.sailing.gwt.ui.shared.WindFieldGenParamsDTO;
|
||||
|
||||
public class SimulatorMap extends AbsolutePanel implements RequiresDataInitialization {
|
||||
|
||||
private MapWidget mapw;
|
||||
private boolean dataInitialized = false;
|
||||
private boolean overlaysInitialized = false;
|
||||
private WindFieldGenParamsDTO windParams = new WindFieldGenParamsDTO();
|
||||
private WindFieldCanvasOverlay windFieldCanvasOverlay = null;
|
||||
private PathCanvasOverlay pathCanvasOverlay = null;
|
||||
private RaceCourseCanvasOverlay raceCourseCanvasOverlay = null;
|
||||
|
||||
private final SimulatorServiceAsync simulatorSvc;
|
||||
private final StringMessages stringMessages;
|
||||
|
||||
private static Logger logger = Logger.getLogger("com.sap.sailing");
|
||||
|
||||
private final int xRes = 5;
|
||||
private final int yRes = 5;
|
||||
|
||||
public enum ViewName {
|
||||
SUMMARY, REPLAY, WINDDISPLAY
|
||||
}
|
||||
|
||||
public SimulatorMap(SimulatorServiceAsync simulatorSvc, StringMessages stringMessages) {
|
||||
this.simulatorSvc = simulatorSvc;
|
||||
this.stringMessages = stringMessages;
|
||||
dataInitialized = false;
|
||||
initializeData();
|
||||
//createOverlays();
|
||||
}
|
||||
|
||||
private void loadMapsAPI() {
|
||||
/*
|
||||
* Asynchronously loads the Maps API.
|
||||
*
|
||||
* The first parameter should be a valid Maps API Key to deploy this application on a public server, but a blank
|
||||
* key will work for an application served from localhost.
|
||||
*/
|
||||
Maps.loadMapsApi("", "2", false, new Runnable() {
|
||||
public void run() {
|
||||
mapw = new MapWidget();
|
||||
//mapw.setUI(SimulatorMapOptions.newInstance());
|
||||
mapw.setZoomLevel(15);
|
||||
// mapw.setSize("100%", "650px");
|
||||
// mapw.setSize("100%", "80%");
|
||||
|
||||
mapw.addControl(new LargeMapControl3D(), new ControlPosition(ControlAnchor.TOP_RIGHT, /* offsetX */0, /* offsetY */
|
||||
30));
|
||||
mapw.addControl(new MenuMapTypeControl());
|
||||
mapw.addControl(new ScaleControl(), new ControlPosition(ControlAnchor.BOTTOM_RIGHT, /* offsetX */10, /* offsetY */
|
||||
20));
|
||||
// Add the map to the HTML host page
|
||||
mapw.setScrollWheelZoomEnabled(true);
|
||||
//mapw.setContinuousZoom(true);
|
||||
mapw.setTitle(stringMessages.simulator() + " " + stringMessages.map());
|
||||
PositionDTO kiel = new PositionDTO(54.332700439830454, 10.133256912231445);
|
||||
|
||||
LatLng position = LatLng.newInstance(kiel.latDeg, kiel.lngDeg);
|
||||
mapw.panTo(position);
|
||||
SimulatorMap.this.add(mapw, 0, 0);
|
||||
mapw.setSize("100%", "100%");
|
||||
|
||||
dataInitialized = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void initializeOverlays() {
|
||||
raceCourseCanvasOverlay = new RaceCourseCanvasOverlay();
|
||||
mapw.addOverlay(raceCourseCanvasOverlay);
|
||||
|
||||
windFieldCanvasOverlay = new WindFieldCanvasOverlay();
|
||||
// mapw.addOverlay(windFieldCanvasOverlay);
|
||||
pathCanvasOverlay = new PathCanvasOverlay();
|
||||
overlaysInitialized = true;
|
||||
}
|
||||
|
||||
private void generateWindField(final WindControlParameters wControls) {
|
||||
logger.info("In generateWindField");
|
||||
|
||||
PositionDTO startPointDTO = new PositionDTO(raceCourseCanvasOverlay.startPoint.getLatitude(),
|
||||
raceCourseCanvasOverlay.startPoint.getLongitude());
|
||||
PositionDTO endPointDTO = new PositionDTO(raceCourseCanvasOverlay.endPoint.getLatitude(),
|
||||
raceCourseCanvasOverlay.endPoint.getLongitude());
|
||||
logger.info("StartPoint:" + startPointDTO);
|
||||
windParams.setNorthWest(startPointDTO);
|
||||
windParams.setSouthEast(endPointDTO);
|
||||
windParams.setxRes(xRes);
|
||||
windParams.setyRes(yRes);
|
||||
windParams.setWindBearing(wControls.windBearing);
|
||||
windParams.setWindSpeed(wControls.windSpeed);
|
||||
|
||||
simulatorSvc.getWindField(windParams, new AsyncCallback<WindFieldDTO>() {
|
||||
@Override
|
||||
public void onFailure(Throwable message) {
|
||||
Window.alert("Failed servlet call to SimulatorService\n" + message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(WindFieldDTO wl) {
|
||||
logger.info("Number of windDTO : " + wl.getMatrix().size());
|
||||
refreshWindFieldOverlay(wl);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void refreshWindFieldOverlay(final WindFieldDTO wl) {
|
||||
windFieldCanvasOverlay.setWindField(wl);
|
||||
windFieldCanvasOverlay.redraw(true);
|
||||
}
|
||||
|
||||
private void generatePath(final WindControlParameters wControls) {
|
||||
logger.info("In generatePath");
|
||||
|
||||
PositionDTO startPointDTO = new PositionDTO(raceCourseCanvasOverlay.startPoint.getLatitude(),
|
||||
raceCourseCanvasOverlay.startPoint.getLongitude());
|
||||
PositionDTO endPointDTO = new PositionDTO(raceCourseCanvasOverlay.endPoint.getLatitude(),
|
||||
raceCourseCanvasOverlay.endPoint.getLongitude());
|
||||
|
||||
windParams.setNorthWest(startPointDTO);
|
||||
windParams.setSouthEast(endPointDTO);
|
||||
windParams.setxRes(xRes);
|
||||
windParams.setyRes(yRes);
|
||||
windParams.setWindBearing(wControls.windBearing);
|
||||
windParams.setWindSpeed(wControls.windSpeed);
|
||||
|
||||
simulatorSvc.getPaths(windParams, new AsyncCallback<PathDTO[]>() {
|
||||
@Override
|
||||
public void onFailure(Throwable message) {
|
||||
Window.alert("Failed servlet call to SimulatorService\n" + message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(PathDTO[] paths) {
|
||||
logger.info("Number of Paths : " + paths.length);
|
||||
/* TODO Revisit for now creating a WindFieldDTO from the path */
|
||||
WindFieldDTO pathWindDTO = new WindFieldDTO();
|
||||
pathWindDTO.setMatrix(paths[0].getMatrix());
|
||||
pathCanvasOverlay.setWindField(pathWindDTO);
|
||||
pathCanvasOverlay.redraw(true);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private boolean isCourseSet() {
|
||||
return raceCourseCanvasOverlay.isCourseSet();
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
if (!overlaysInitialized) {
|
||||
initializeOverlays();
|
||||
}
|
||||
mapw.setDoubleClickZoom(false);
|
||||
mapw.removeOverlay(windFieldCanvasOverlay);
|
||||
mapw.removeOverlay(pathCanvasOverlay);
|
||||
raceCourseCanvasOverlay.setSelected(true);
|
||||
// raceCourseCanvasOverlay.setVisible(true);
|
||||
raceCourseCanvasOverlay.reset();
|
||||
raceCourseCanvasOverlay.redraw(true);
|
||||
}
|
||||
|
||||
private void refreshSummaryView(WindControlParameters wControls) {
|
||||
mapw.removeOverlay(windFieldCanvasOverlay);
|
||||
pathCanvasOverlay.displayWindAlongPath = true;
|
||||
mapw.addOverlay(pathCanvasOverlay);
|
||||
generatePath(wControls);
|
||||
}
|
||||
|
||||
private void refreshReplayView(WindControlParameters wControls) {
|
||||
|
||||
mapw.addOverlay(windFieldCanvasOverlay);
|
||||
pathCanvasOverlay.displayWindAlongPath = false;
|
||||
mapw.addOverlay(pathCanvasOverlay);
|
||||
generateWindField(wControls);
|
||||
generatePath(wControls);
|
||||
}
|
||||
|
||||
private void refreshWindDisplayView(WindControlParameters wControls) {
|
||||
mapw.removeOverlay(pathCanvasOverlay);
|
||||
mapw.addOverlay(windFieldCanvasOverlay);
|
||||
generateWindField(wControls);
|
||||
}
|
||||
|
||||
public void refreshView(ViewName name, WindControlParameters wControls) {
|
||||
if (!overlaysInitialized) {
|
||||
initializeOverlays();
|
||||
}
|
||||
if (isCourseSet()) {
|
||||
mapw.setDoubleClickZoom(true);
|
||||
raceCourseCanvasOverlay.setSelected(false);
|
||||
switch (name) {
|
||||
case SUMMARY:
|
||||
refreshSummaryView(wControls);
|
||||
break;
|
||||
case REPLAY:
|
||||
refreshReplayView(wControls);
|
||||
break;
|
||||
case WINDDISPLAY:
|
||||
refreshWindDisplayView(wControls);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
Window.alert("No course set, please initialize the course with Start-End Input");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initializeData() {
|
||||
loadMapsAPI();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDataInitialized() {
|
||||
return dataInitialized;
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package com.sap.sailing.gwt.ui.simulator;
|
||||
|
||||
|
||||
public class WindControlParameters {
|
||||
public double windSpeed = 7.2;
|
||||
public double windBearing = 0;
|
||||
|
||||
public WindControlParameters() {
|
||||
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -45,7 +45,7 @@ public class WindFieldMouseMoveHandler implements MouseMoveHandler {
|
||||
|
||||
@Override
|
||||
public void onMouseMove(MouseMoveEvent event) {
|
||||
logger.info("In MouseMove");
|
||||
//logger.info("In MouseMove");
|
||||
|
||||
if (windFieldPoints == null) {
|
||||
return;
|
||||
@@ -60,7 +60,7 @@ public class WindFieldMouseMoveHandler implements MouseMoveHandler {
|
||||
}
|
||||
|
||||
if (windFieldPoints.containsKey(point)) {
|
||||
logger.info("Found Point");
|
||||
//logger.info("Found Point");
|
||||
lastToolx = x;
|
||||
lastTooly = y;
|
||||
lastImageData = context2d.getImageData(x, y, ToolTip.toolRectW, ToolTip.toolRectH);
|
||||
|
||||
Reference in new issue
Block a user