/** * Getter for <code>RoomMap</code> object with all its properties, including <code>Receiver</code> * s and <code>CoordinateZeroMarkerView</code>s . * * @return the map * @see Receiver * @see ReceiverView * @see CoordinateZeroMarkerView */ public RoomMap getMap() { // set zero coordinate marker positions int lowerLeftMarkerOffsetXInPixels = (int) (lowerLeftMarker.getLocation().getX() / scalingRatioToFitContainer); int lowerLeftMarkerOffsetYInPixels = (int) (lowerLeftMarker.getLocation().getY() / scalingRatioToFitContainer) + (CoordinateZeroMarkerView.ZERO_COORDINATE_MARKER_VIEW_HEIGHT); map.setLowerLeftMarkerOffsetXInPixels(lowerLeftMarkerOffsetXInPixels); map.setLowerLeftMarkerOffsetYInPixels(lowerLeftMarkerOffsetYInPixels); int upperRightMarkerOffsetXInPixels = (int) (upperRightMarker.getLocation().getX() / scalingRatioToFitContainer) + (CoordinateZeroMarkerView.ZERO_COORDINATE_MARKER_VIEW_WIDTH); int upperRightMarkerOffsetYInPixels = (int) (upperRightMarker.getLocation().getY() / scalingRatioToFitContainer); map.setUpperRightMarkerOffsetXInPixels(upperRightMarkerOffsetXInPixels); map.setUpperRightMarkerOffsetYInPixels(upperRightMarkerOffsetYInPixels); // set room width and height in meters double roomWidthInMeters = parent.getRoomWidthInMeters(); double roomHeightInMeters = parent.getRoomHeightInMeters(); map.setWidthInMeters(roomWidthInMeters); map.setHeightInMeters(roomHeightInMeters); // set width and height ratios int mapWidthInPixels = upperRightMarkerOffsetXInPixels - lowerLeftMarkerOffsetXInPixels; int mapHeightInPixels = lowerLeftMarkerOffsetYInPixels - upperRightMarkerOffsetYInPixels; double mapWidthRatio = (mapWidthInPixels) / roomWidthInMeters; double mapHeightRatio = (mapHeightInPixels) / roomHeightInMeters; map.setRatioWidth(mapWidthRatio); map.setRatioHeight(mapHeightRatio); // set receiver positions in meters map.getReceivers().clear(); // first we remove all present receivers for (ReceiverView receiverView : receiverViews) { int receiverViewXInPixels = ((int) (receiverView.getLocation().getX() / scalingRatioToFitContainer)) + (ReceiverView.RECEIVER_ITEM_WIDTH / 2); int receiverViewYInPixels = ((int) (receiverView.getLocation().getY() / scalingRatioToFitContainer)) + (ReceiverView.RECEIVER_ITEM_HEIGHT / 2); double receiverPositionInMetersX = calculateReceiverPositionInMetersX( lowerLeftMarkerOffsetXInPixels, receiverViewXInPixels, mapWidthRatio); double receiverPositionInMetersY = calculateReceiverPositionInMetersY( lowerLeftMarkerOffsetYInPixels, receiverViewYInPixels, mapHeightRatio); receiverView.getReceiver().setxPos(receiverPositionInMetersX); receiverView.getReceiver().setyPos(receiverPositionInMetersY); map.addReceiver(receiverView.getReceiver()); } // set map title String titleFromInput = parent.getRoomTitle(); map.setTitle(titleFromInput.equals("") ? "Unkown" : titleFromInput); // set map xFrom, xTo, yFrom and yTo values map.setxFrom(0); map.setxTo(map.getWidthInMeters()); map.setyFrom(0); map.setyTo(map.getHeightInMeters()); Application.getApplication().setRoomMap(map); return map; }
private void uploadMapToServer(RoomMap newMap) { Mongo mongo = null; DB database; DBCollection sampleData; String databaseAddress = DEFAULT_DATABASE_ADDRESS; try { // read parameters from the configuration file databaseAddress = Utilities.getConfigurationValue(DATABASE_ADDRESS); } catch (NumberFormatException exception) { // reading has failed, use default values logger.info( "Reading parameters from configuration file failed. " + "Using default values for database_address instead."); } try { mongo = new Mongo(databaseAddress); } catch (UnknownHostException e1) { e1.printStackTrace(); } database = mongo.getDB("rssiSystem"); sampleData = database.getCollection("map_records"); // remove all maps sampleData.drop(); SimpleDateFormat simpledateformat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); String strDate = simpledateformat.format(new Date()); // ------------------- // Load our image byte[] imageBytes = null; try { imageBytes = Utilities.LoadImageAsBytes(newMap.getPath()); } catch (Exception e1) { e1.printStackTrace(); } // --------------------- // Create GridFS object GridFS fs = new GridFS(database); // Save image into database GridFSInputFile in = fs.createFile(imageBytes); in.save(); Object mapIdObject = in.getId(); // System.out.println(mapIdObject); try { DBObject documentDetail = new BasicDBObject(); documentDetail.put("_cls", "mapRecords"); // for mongoEngine ORM users documentDetail.put("image", mapIdObject); documentDetail.put("mapId", newMap.getId()); documentDetail.put("width", newMap.getWidthInMeters()); documentDetail.put("height", newMap.getHeightInMeters()); documentDetail.put("offsetX", newMap.getLowerLeftMarkerOffsetXInPixels()); documentDetail.put("offsetY", newMap.getLowerLeftMarkerOffsetYInPixels()); documentDetail.put("offset2X", newMap.getUpperRightMarkerOffsetXInPixels()); documentDetail.put("offset2Y", newMap.getUpperRightMarkerOffsetYInPixels()); documentDetail.put("scalingX", newMap.getRatioWidth()); documentDetail.put("scalingY", newMap.getRatioHeight()); documentDetail.put("title", newMap.getTitle()); documentDetail.put("updateTime", strDate); sampleData.insert(documentDetail); } catch (Exception e) { e.printStackTrace(); } }