public void zoomToGarminGeo(double factor, int longitude, int latitude) { Point2D.Double mapCoord = new Point2D.Double(); COORD tempCoord = transformer.createTempCoord(); transformer.wgs84ToMap( CoordUtils.toWGS84Rad(longitude), CoordUtils.toWGS84Rad(latitude), tempCoord, mapCoord); zoom(factor, (int) mapCoord.getX(), (int) mapCoord.getY()); }
public void setPosition(double minLon, double maxLon, double minLat, double maxLat) { transformer.resetAutoScale(); transformer.adjustAutoScaleFromWgs84(minLon, minLat); transformer.adjustAutoScaleFromWgs84(maxLon, maxLat); transformer.fixAspectRatio(); transformerChanged(); repaint(); }
public void saveMapAs( final File selectedFile, FileExporter exporter, MapTransformer<COORD> transformer) throws IOException { exporter.setup(selectedFile, transformer.getWidth(), transformer.getHeight()); final Graphics2D g2 = exporter.getG2(); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setColor(MapPanel.BG_COLOR); g2.fillRect(0, 0, transformer.getWidth(), transformer.getHeight()); Rectangle bbox = transformer.getGarminBoundingBox(); int minLon = bbox.x; int maxLon = bbox.x + bbox.width; int minLat = bbox.y; int maxLat = bbox.y + bbox.height; int resolution = getResolution(minLon, maxLon, transformer.getWidth()); TransformedMapListener drawer = createMapDrawer(new MapConfig(), g2, exporter.getFontSize(), transformer); MapListener listener = new CoordinateConverterListener<COORD>( transformer, new ClippingMapListener(0, transformer.getWidth(), 0, transformer.getHeight(), drawer)); map.readMapForDrawing(minLon, maxLon, minLat, maxLat, resolution, ObjectKind.ALL, listener); exporter.finishSave(); }
/** Zoom and position the map in order to see everything. */ public void showAllMap() { transformer.resetAutoScale(); try { transformer.adjustAutoScaleFromWgs84( CoordUtils.toWGS84Rad(map.getMinLongitude()), CoordUtils.toWGS84Rad(map.getMinLatitude())); transformer.adjustAutoScaleFromWgs84( CoordUtils.toWGS84Rad(map.getMaxLongitude()), CoordUtils.toWGS84Rad(map.getMaxLatitude())); } catch (IOException e) { e.printStackTrace(); } transformer.fixAspectRatio(); transformerChanged(); }
@Test public void shouldTransformTheSubFormsInAGivenMap() throws JsonProcessingException { Map<String, Object> transformedMap = mapTransformer.transform(formData); assertEquals("demo1", transformedMap.get("anmId")); assertNotNull(transformedMap.get(SUB_FORMS)); List<Map<String, Object>> subForms = (List<Map<String, Object>>) transformedMap.get(SUB_FORMS); assertEquals(3, subForms.size()); Map<String, Object> subForm1 = subForms.get(0); assertEquals("child_registration_oa", subForm1.get(NAME)); assertEquals("male", subForm1.get("gender")); assertEquals("bcg opv_0 hepb_0", subForm1.get("immunizationsGiven")); Map<String, Object> subForm2 = subForms.get(1); assertEquals("one_more_registration", subForm2.get(NAME)); assertEquals("harry", subForm2.get("firstName")); assertEquals("1988-07-31", subForm2.get("dob")); Map<String, Object> subForm3 = subForms.get(2); assertEquals("one_more_registration", subForm3.get(NAME)); assertEquals("ron", subForm3.get("firstName")); }
@Test public void shouldTransformTheGivenMap() throws JsonProcessingException { Map<String, Object> transformedMap = mapTransformer.transform(formData); assertEquals("demo1", transformedMap.get("anmId")); assertEquals("pnc_registration_oa", transformedMap.get(FORM_NAME)); assertEquals("99f42bc6-1fc2-4b67-8917-924335e1972f", transformedMap.get("motherId")); assertEquals("2013-08-07", transformedMap.get("registrationDate")); assertEquals(null, transformedMap.get("aadhaarNumber")); assertEquals(null, transformedMap.get("deliveryOutcome")); }
public String getInfo(int x, int y, int maxNbInfo) { Point2D.Double wgs84 = new Point2D.Double(); transformer.map2wgs84(x, y, wgs84); Point2D.Double wgs84Precision = new Point2D.Double(); transformer.map2wgs84(x + 5, y, wgs84Precision); int longitude = CoordUtils.fromWGS84Rad(wgs84.x); int latitude = CoordUtils.fromWGS84Rad(wgs84.y); int precision = Math.max( Math.abs(longitude - CoordUtils.fromWGS84Rad(wgs84Precision.x)), Math.abs(latitude - CoordUtils.fromWGS84Rad(wgs84Precision.y))); try { FindObjectByPositionListener listener = new FindObjectByPositionListener(longitude, latitude, precision); int resolution = getResolution(transformer); map.readMapForDrawing( longitude, longitude, latitude, latitude, resolution, ObjectKind.ALL, listener); List<FoundObject> founds = listener.getFounds(); if (founds.isEmpty()) return null; StringBuilder buffer = new StringBuilder("<html>\n<ul>\n"); for (int i = founds.size() - 1; i >= Math.max(0, founds.size() - maxNbInfo); i--) { FoundObject found = founds.get(i); buffer.append(" <li>"); found.toDebugHtml(buffer); buffer.append("</li>\n"); } buffer.append("</ul>\n</html>\n"); return buffer.toString(); } catch (IOException e) { e.printStackTrace(); return null; } }
public void paintComponent(Graphics g) { super.paintComponent(g); if (transformer.isSetupDone()) { thread.checkSetup(transformer, config); Graphics2D g2 = ((Graphics2D) g.create()); // paint the background g2.setColor(MapPanel.BG_COLOR); g2.fillRect(0, 0, getWidth(), getHeight()); MapPanelThread.PaintInfo paintInfo = thread.getPaintInfo(transformer); if (paintInfo != null) { /*g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);*/ g2.drawImage(paintInfo.image, paintInfo.x, paintInfo.y, paintInfo.w, paintInfo.h, this); } } }
/** Create a dependent MapPanel, with its converter and maps provided from outside. */ public MapPanel(ImgFilesBag map, MapTransformer<COORD> transformer) { this.map = map; this.transformer = transformer; thread = new MapPanelThread<COORD>(this, config); thread.start(); addComponentListener( new ComponentListener() { public void componentResized(ComponentEvent e) { MapPanel.this.componentResized(); } public void componentMoved(ComponentEvent e) {} public void componentShown(ComponentEvent e) {} public void componentHidden(ComponentEvent e) {} }); transformer.setDimensions(getWidth(), getHeight()); }
public void componentResized() { if (transformer.setDimensions(getWidth(), getHeight())) { transformerChanged(); } }
public int getResolution(MapTransformer<COORD> transformer) { Rectangle bbox = transformer.getGarminBoundingBox(); int minLon = bbox.x; int maxLon = bbox.x + bbox.width; return getResolution(minLon, maxLon, transformer.getWidth()); }
public void zoom(double factor) { transformer.zoom(factor); transformerChanged(); repaint(); }
/** If factor>1 zoom in, otherwise zoom out. */ public void zoom(double factor, int x, int y) { transformer.zoom(factor, x, y); transformerChanged(); repaint(); }
public void movePosition(double deltaX, double deltaY) { transformer.moveMapPosition(deltaX, deltaY); transformerChanged(); repaint(); }