Knowledge Base Nr: 00334 trackmap.java - http://www.swe-kaiser.de

Downloads:

Java: GWT: tracking in maps skaliert anzeigen

  
public static void DoDrawTrack(MapWidget map, String sPoints, double fBounds[])
{
double fLongMax = fBounds[0];
double fLongMin = fBounds[1];
double fLatMax = fBounds[2];
double fLatMin = fBounds[3];

String pt[] = sPoints.split("#");
if (pt.length < 2)
return;

String val[] = pt[0].split(" ");
if (val.length < 2)
return;

LatLng points[] = new LatLng[pt.length];

for (int n = 0; n < pt.length; n++)
{
String sCoord[] = pt[n].split(" ");

double fLong = Double.parseDouble(sCoord[0]);
double fLat = Double.parseDouble(sCoord[1]);

points[n] = LatLng.newInstance(fLong, fLat);

if (fLong > fLongMax) fLongMax = fLong;
if (fLong < fLongMin) fLongMin = fLong;
if (fLat > fLatMax) fLatMax = fLat;
if (fLat < fLatMin) fLatMin = fLat;
}

Polyline pLine = new Polyline(points, CDefines.TRACKING_COLOR, CDefines.TRACKING_LINEWIDTH);
map.addOverlay(pLine);

fBounds[0] = fLongMax;
fBounds[1] = fLongMin;
fBounds[2] = fLatMax;
fBounds[3] = fLatMin;
}

public static void DoResizeAndCenterMap(MapWidget map, double fLongMin, double fLongMax, double fLatMin, double fLatMax)
{
if (map == null)
return;

double fOffset = CDefines.VEHICLE_POSITIONS_MAP_OFFSET;

LatLng sw = LatLng.newInstance(fLongMin-fOffset, fLatMin-fOffset);
LatLng ne = LatLng.newInstance(fLongMax+fOffset, fLatMax+fOffset);
LatLngBounds bounds = LatLngBounds.newInstance(sw, ne);
int nZoomLevel = map.getBoundsZoomLevel(bounds);
LatLng llCenter = bounds.getCenter();

map.setCenter(llCenter, nZoomLevel);
}

public static void ShowTrack(String sPoints);
{
double fBounds[] = new double[4];
fBounds[0] = fLongMax;
fBounds[1] = fLongMin;
fBounds[2] = fLatMax;
fBounds[3] = fLatMin;

DoDrawTrack(m_map, sPoints, fBounds);

fLongMax = fBounds[0];
fLongMin = fBounds[1];
fLatMax = fBounds[2];
fLatMin = fBounds[3];

String sPosition = m_arrJobData[i].m_strGPSData;
ShowPosition("TRACK", sPosition, "");

DoResizeAndCenterMap(m_map, fLongMin, fLongMax, fLatMin, fLatMax);
}

private void ShowPosition(String sEvent, String sPosition, String sText)
{
String sCoord[] = sPosition.split(" ");
if (sCoord.length != 2)
return;

double fLong = Double.parseDouble(sCoord[0]);
double fLat = Double.parseDouble(sCoord[1]);

HTML html = new HTML("<b>" + sEvent + "</b><br /><p>" + sText + "</p><p>" + sPosition.replace(" ", ", ") + "</p>");

if ((m_map != null) && m_dockMap.isVisible())
{
m_point = LatLng.newInstance(fLong, fLat);
m_map.addOverlay(new Marker(m_point));
m_map.setCenter(m_point);

m_map.getInfoWindow().open(m_map.getCenter(), new InfoWindowContent(html));
}

m_imgPanel.setVisible(false);
m_dockMap.setVisible(true);
}


MapWidget m_map = null;
DockLayoutPanel m_dockMap = null;
LatLng m_point = null;

private void createMapPanel()
{
//firmenstandort
//m_point = LatLng.newInstance(m_mf.m_p.m_fGPSHomeLat, m_mf.m_p.m_fGPSHomeLong);
m_point = LatLng.newInstance(m_mf.m_p.m_CustomerData.GetLat(), m_mf.m_p.m_CustomerData.GetLon());

m_map = new MapWidget(m_point, CDefines.JOB_DATA_MAP_START_ZOOM);
m_map.setSize("100%", "100%");

// Add some controls for the zoom level
m_map.addControl(new LargeMapControl());

// Add a marker
m_map.addOverlay(new Marker(m_point));

// Add an info window to highlight a point of interest
HTML html = new HTML(CDefines.JOB_DATA_MAP_HOME_TEXT);

m_map.getInfoWindow().open(m_map.getCenter(),
new InfoWindowContent(html));

m_dockMap = new DockLayoutPanel(Unit.PX);
m_dockMap.addNorth(m_map, CDefines.JOB_DATA_MAP_HEIGHT);
m_dockMap.setStyleName("jobdata-mapview");

m_centerpanel.add(m_dockMap);
}

public void Init()
{
Maps.loadMapsApi("", "2", false, new Runnable() {
public void run() {
createMapPanel();
}
});
}