From: Marc Englund Date: Fri, 21 Sep 2007 12:43:35 +0000 (+0000) Subject: Map integration; really using db data. X-Git-Tag: 6.7.0.beta1~5962 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=0b248bdc8cb04d4cc6fcac4359ebcb1153e6d3d6;p=vaadin-framework.git Map integration; really using db data. svn changeset:2367/svn branch:trunk --- diff --git a/src/com/itmill/toolkit/demo/reservation/GoogleMap.java b/src/com/itmill/toolkit/demo/reservation/GoogleMap.java index 68402a4ed6..0869cf5b64 100644 --- a/src/com/itmill/toolkit/demo/reservation/GoogleMap.java +++ b/src/com/itmill/toolkit/demo/reservation/GoogleMap.java @@ -20,7 +20,7 @@ public class GoogleMap extends AbstractComponent implements Sizeable, private int width = 400; private int height = 300; private int zoomLevel = 15; - private Point2D.Float mapCenter; + private Point2D.Double mapCenter; private Container dataSource; private Object itemMarkerHtmlPropertyId = new Object(); @@ -48,15 +48,15 @@ public class GoogleMap extends AbstractComponent implements Sizeable, Object itemId = it.next(); Item item = this.dataSource.getItem(itemId); Property p = item.getItemProperty(getItemMarkerXPropertyId()); - Float x = (Float) (p != null ? p.getValue() : null); + Double x = (Double) (p != null ? p.getValue() : null); p = item.getItemProperty(getItemMarkerYPropertyId()); - Float y = (Float) (p != null ? p.getValue() : null); + Double y = (Double) (p != null ? p.getValue() : null); if (x == null || y == null) { continue; } target.startTag(TAG_MARKER); - target.addAttribute("x", x.floatValue()); - target.addAttribute("y", y.floatValue()); + target.addAttribute("x", x.doubleValue()); + target.addAttribute("y", y.doubleValue()); p = item.getItemProperty(getItemMarkerHtmlPropertyId()); String h = (String) (p != null ? p.getValue() : null); target.addAttribute("html", h); @@ -111,11 +111,11 @@ public class GoogleMap extends AbstractComponent implements Sizeable, throw new UnsupportedOperationException(); } - public void setMapCenter(Point2D.Float center) { + public void setMapCenter(Point2D.Double center) { this.mapCenter = center; } - public Point2D.Float getMapCenter() { + public Point2D.Double getMapCenter() { return this.mapCenter; } @@ -163,7 +163,7 @@ public class GoogleMap extends AbstractComponent implements Sizeable, // Marker add - public Object addMarker(String html, Point2D.Float location) { + public Object addMarker(String html, Point2D.Double location) { if (location == null) { throw new IllegalArgumentException("Location must be non-null"); } @@ -176,9 +176,9 @@ public class GoogleMap extends AbstractComponent implements Sizeable, } Item marker = this.dataSource.getItem(markerId); Property p = marker.getItemProperty(getItemMarkerXPropertyId()); - p.setValue(new Float(location.x)); + p.setValue(new Double(location.x)); p = marker.getItemProperty(getItemMarkerYPropertyId()); - p.setValue(new Float(location.y)); + p.setValue(new Double(location.y)); p = marker.getItemProperty(getItemMarkerHtmlPropertyId()); p.setValue(html); @@ -208,8 +208,12 @@ public class GoogleMap extends AbstractComponent implements Sizeable, this.dataSource.addContainerProperty(this.itemMarkerHtmlPropertyId, String.class, null); this.dataSource.addContainerProperty(this.itemMarkerXPropertyId, - Float.class, new Float(0)); + Double.class, new Double(0)); this.dataSource.addContainerProperty(this.itemMarkerYPropertyId, - Float.class, new Float(0)); + Double.class, new Double(0)); + } + + public void clear() { + setContainerDataSource(null); } } \ No newline at end of file diff --git a/src/com/itmill/toolkit/demo/reservation/ReservationApplication.java b/src/com/itmill/toolkit/demo/reservation/ReservationApplication.java index 42ebd7d74c..4c36e82bf0 100644 --- a/src/com/itmill/toolkit/demo/reservation/ReservationApplication.java +++ b/src/com/itmill/toolkit/demo/reservation/ReservationApplication.java @@ -1,6 +1,7 @@ package com.itmill.toolkit.demo.reservation; import java.awt.Point; +import java.awt.geom.Point2D; import java.util.Date; import java.util.Iterator; import java.util.List; @@ -38,6 +39,8 @@ public class ReservationApplication extends Application { private Table allTable; private CalendarField allCalendar; + private GoogleMap map; + public void init() { db = new SampleDB(true); db.generateResources(); @@ -80,18 +83,18 @@ public class ReservationApplication extends Application { infoLayout.addComponent(reservationButton); statusLabel = new Label(); infoLayout.addComponent(statusLabel); - + // TODO map - GoogleMap map = new GoogleMap(); + map = new GoogleMap(); map.setWidth(290); map.setHeight(150); - map.setZoomLevel(2); - //map.setMapCenter(new Point.Float(60.453380f, 22.301850f)); + map.setZoomLevel(12); + map.setItemMarkerHtmlPropertyId(SampleDB.Resource.PROPERTY_ID_NAME); + map.setItemMarkerXPropertyId(SampleDB.Resource.PROPERTY_ID_LOCATIONX); + map.setItemMarkerYPropertyId(SampleDB.Resource.PROPERTY_ID_LOCATIONY); + map.setContainerDataSource(db.getResources(null)); infoLayout.addComponent(map); - - map.addMarker("IT Mill", new Point.Float(60.453380f, 22.301850f)); - map.addMarker("Romson a.k.a Rodskar", new Point.Float(63.509433f,22.276711f)); - + // TODO Use calendar, set following hour Date now = new Date(); reservedFrom = new CalendarField(); @@ -133,7 +136,8 @@ public class ReservationApplication extends Application { reservedTo.setImmediate(true); reservedTo.setValue(now); - OrderedLayout allLayout = new OrderedLayout(OrderedLayout.ORIENTATION_HORIZONTAL); + OrderedLayout allLayout = new OrderedLayout( + OrderedLayout.ORIENTATION_HORIZONTAL); allCalendar = new CalendarField(); initCalendarFieldPropertyIds(allCalendar); allLayout.addComponent(allCalendar); @@ -195,7 +199,7 @@ public class ReservationApplication extends Application { Container allReservations = db.getReservations(null); allTable.setContainerDataSource(allReservations); allCalendar.setContainerDataSource(allReservations); - + } private void refreshSelectedResources() { @@ -207,12 +211,28 @@ public class ReservationApplication extends Application { reservationButton.setEnabled(false); return; } + map.clear(); if (resource == null) { resourceName.setValue("Choose resource"); reservationButton.setEnabled(false); + map.setContainerDataSource(db.getResources(null)); + map.setZoomLevel(12); } else { - resourceName.setValue((String) resource.getItemProperty( - SampleDB.Resource.PROPERTY_ID_NAME).getValue()); + String name = (String) resource.getItemProperty( + SampleDB.Resource.PROPERTY_ID_NAME).getValue(); + String desc = (String) resource.getItemProperty( + SampleDB.Resource.PROPERTY_ID_DESCRIPTION).getValue(); + resourceName.setValue(name); + Double x = (Double) resource.getItemProperty( + SampleDB.Resource.PROPERTY_ID_LOCATIONX).getValue(); + Double y = (Double) resource.getItemProperty( + SampleDB.Resource.PROPERTY_ID_LOCATIONY).getValue(); + if (x != null && y != null) { + map.addMarker(name + "
" + desc, new Point2D.Double(x + .doubleValue(), y.doubleValue())); + map.setZoomLevel(14); + } + reservationButton.setEnabled(true); } @@ -222,8 +242,7 @@ public class ReservationApplication extends Application { cal .setItemStartPropertyId(SampleDB.Reservation.PROPERTY_ID_RESERVED_FROM); cal.setItemEndPropertyId(SampleDB.Reservation.PROPERTY_ID_RESERVED_TO); - cal - .setItemTitlePropertyId(SampleDB.Resource.PROPERTY_ID_NAME); + cal.setItemTitlePropertyId(SampleDB.Resource.PROPERTY_ID_NAME); cal .setItemDescriptionPropertyId(SampleDB.Reservation.PROPERTY_ID_DESCRIPTION); } diff --git a/src/com/itmill/toolkit/demo/reservation/SampleDB.java b/src/com/itmill/toolkit/demo/reservation/SampleDB.java index bc1f5b04e9..7e0507db46 100644 --- a/src/com/itmill/toolkit/demo/reservation/SampleDB.java +++ b/src/com/itmill/toolkit/demo/reservation/SampleDB.java @@ -372,28 +372,47 @@ public class SampleDB { } public void generateResources() { - String[][] resources = { - { "IT Mill Toolkit Manual", "the manual", "Books" }, + /* + * map.addMarker("Old Mill", new Point.Double(60.452224f,22.299929f)); + * map.addMarker("ICT", new Point.Double(60.449007f,22.295508f)); + * map.addMarker("DataCity", new Point.Double(60.448329f,22.295165f)); + * map.addMarker("BioCity", new Point.Double(60.449451f,22.293105f)); + * map.addMarker("PharmaCity", new Point.Double(60.44888f,22.292032f)); + * map.addMarker("Intelligate", new Point.Double(60.450403f,22.29495f)); + * map.addMarker("Paviljonki", new Point.Double(60.445408f,22.290831f)); + * map.addMarker("Trivium", new Point.Double(60.44641962165445f, + * 22.301753170493f)); map.addMarker("Linja-auto asema", new + * Point.Double(60.457049f,22.267957f)); + */ + + Object[][] resources = { + { "IT Mill Toolkit Manual", "the manual", "Books", new Double(60.452224),new Double(22.299929)}, { "IT Mill Toolkit for Dummies", "the hardcover version", - "Books" }, - { "Sony", "Old Sony video projector", "AV equipment" }, - { "Sanyo", "Brand new hd-ready video projector", "AV equipment" }, - { "Room 7", "Converence room in the lobby", "Conference rooms" }, + "Books", new Double(60.452224),new Double(22.299929) }, + { "Sony", "Old Sony video projector", "AV equipment", new Double(60.449007),new Double(22.295508) }, + { "Sanyo", "Brand new hd-ready video projector", "AV equipment", new Double(60.452224),new Double(22.299929) }, + { "Room 7", "Conference room in the lobby", "Conference rooms", new Double(60.449451),new Double(22.292032) }, { "Luokkahuone", "Classroom right next to IT Mill", - "Conference rooms" }, - { "Nintendo Wii", "Teh uber fun", "Entertainment" }, - { "Playstation", "We don't actually have one", "Entertainment" } }; + "Conference rooms", new Double(60.44888),new Double(22.292032) }, + { "Nintendo Wii", "Teh uber fun", "Entertainment", new Double(60.445408),new Double(22.290831) }, + { "Playstation", "We don't actually have one", "Entertainment", new Double(60.44641962165445),new Double(22.301753170493) } }; String q = "INSERT INTO " + Resource.TABLE + "(" + Resource.PROPERTY_ID_NAME + "," + Resource.PROPERTY_ID_DESCRIPTION + "," - + Resource.PROPERTY_ID_CATEGORY + ")" + " VALUES (?,?,?)"; + + Resource.PROPERTY_ID_CATEGORY + "," + + Resource.PROPERTY_ID_LOCATIONX + "," + + Resource.PROPERTY_ID_LOCATIONY + + ")" + " VALUES (?,?,?,?,?)"; try { PreparedStatement stmt = connection.prepareStatement(q); for (int i = 0; i < resources.length; i++) { - stmt.setString(1, resources[i][0]); - stmt.setString(2, resources[i][1]); - stmt.setString(3, resources[i][2]); + int j=0; + stmt.setString(j+1, (String)resources[i][j++]); + stmt.setString(j+1, (String)resources[i][j++]); + stmt.setString(j+1, (String)resources[i][j++]); + stmt.setDouble(j+1, ((Double)resources[i][j++]).doubleValue()); + stmt.setDouble(j+1, ((Double)resources[i][j++]).doubleValue()); stmt.execute(); } } catch (SQLException e) { diff --git a/src/com/itmill/toolkit/demo/reservation/gwt/client/ui/IGoogleMap.java b/src/com/itmill/toolkit/demo/reservation/gwt/client/ui/IGoogleMap.java index e7d6091174..621b81242b 100644 --- a/src/com/itmill/toolkit/demo/reservation/gwt/client/ui/IGoogleMap.java +++ b/src/com/itmill/toolkit/demo/reservation/gwt/client/ui/IGoogleMap.java @@ -28,6 +28,7 @@ public class IGoogleMap extends GMap2Widget implements Paintable { } public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { + map.clearOverlays(); GLatLng pos = null; for (Iterator it = uidl.getChildIterator(); it.hasNext();) { UIDL u = (UIDL) it.next(); @@ -36,8 +37,8 @@ public class IGoogleMap extends GMap2Widget implements Paintable { for (Iterator m = u.getChildIterator(); m.hasNext();) { UIDL umarker = (UIDL) m.next(); String html = umarker.getStringAttribute("html"); - float x = umarker.getFloatAttribute("x"); - float y = umarker.getFloatAttribute("y"); + double x = umarker.getDoubleAttribute("x"); + double y = umarker.getDoubleAttribute("y"); pos = new GLatLng(x, y); GMarker marker = new GMarker(pos); map.addOverlay(marker); @@ -57,8 +58,8 @@ public class IGoogleMap extends GMap2Widget implements Paintable { map.setZoom(uidl.getIntAttribute("zoom")); } if (uidl.hasAttribute("centerX") && uidl.hasAttribute("centerY")) { - GLatLng center = new GLatLng(uidl.getFloatAttribute("centerX"), - uidl.getFloatAttribute("centerY")); + GLatLng center = new GLatLng(uidl.getDoubleAttribute("centerX"), + uidl.getDoubleAttribute("centerY")); map.setCenter(center); } else if (pos!=null) { // use last marker position