Changeset 32095 in osm for applications/editors/josm/plugins/seachart/jrender
- Timestamp:
- 2016-03-05T11:40:02+01:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/seachart/jrender/src/jrender/Jrender.java
r32090 r32095 27 27 import javax.imageio.ImageIO; 28 28 29 import org.apache.batik.dom.GenericDOMImplementation;30 import org.apache.batik.svggen.SVGGraphics2D;31 import org.w3c.dom.DOMImplementation;32 import org.w3c.dom.Document;33 34 29 import s57.S57map; 35 30 import s57.S57osm; … … 56 51 57 52 public Context () { 58 top = (1.0 - Math.log(Math.tan(map.bounds.maxlat) + 1.0 / Math.cos(map.bounds.maxlat)) / Math.PI) / 2.0 * 256.0 * 4096.0; 59 mile = 768/ ((Math.toDegrees(map.bounds.maxlat) - Math.toDegrees(map.bounds.minlat)) * 60);53 top = (1.0 - Math.log(Math.tan(map.bounds.maxlat) + 1.0 / Math.cos(map.bounds.maxlat)) / Math.PI) / 2.0 * 256.0 * 4096.0 * Math.pow(2, (zoom - 12)); 54 mile = (2 * ((zoom < 12) ? (256 / (int)(Math.pow(2, (11 - zoom)))) : 256) + 256) / ((Math.toDegrees(map.bounds.maxlat) - Math.toDegrees(map.bounds.minlat)) * 60); 60 55 } 61 56 62 57 public Point2D getPoint(Snode coord) { 63 double x = (Math.toDegrees(coord.lon) - Math.toDegrees(map.bounds.minlon)) * 256.0 * 2048.0 / 180.0; 64 double y = ((1.0 - Math.log(Math.tan(coord.lat) + 1.0 / Math.cos(coord.lat)) / Math.PI) / 2.0 * 256.0 * 4096.0) - top; 58 double x = (Math.toDegrees(coord.lon) - Math.toDegrees(map.bounds.minlon)) * 256.0 * 2048.0 * Math.pow(2, (zoom - 12)) / 180.0; 59 double y = ((1.0 - Math.log(Math.tan(coord.lat) + 1.0 / Math.cos(coord.lat)) / Math.PI) / 2.0 * 256.0 * 4096.0 * Math.pow(2, (zoom - 12))) - top; 65 60 return new Point2D.Double(x, y); 66 61 } … … 83 78 } 84 79 85 static final boolean test = true; 86 87 public static void tileMap(String idir, int zoom) throws IOException { 88 BufferedImage img; 89 context = new Context(); 90 91 int border = 256 / (int)Math.pow(2, (12 - zoom)); 92 int size = 256; 93 for (int i = 0; i < (12 - zoom); i++) size *= 2; 94 Rectangle rect = new Rectangle((size + (2 * border)), (size + (2 * border))); 95 img = new BufferedImage(rect.width, rect.height, BufferedImage.TYPE_INT_ARGB); 96 Renderer.reRender(img.createGraphics(), rect, zoom, 1.0, map, context); 97 ByteArrayOutputStream bos = new ByteArrayOutputStream(); 98 ImageIO.write(img, "png", bos); 99 empty = bos.size(); 100 101 if (test) { 102 for (int z = 12; z <= 18; z++) { 103 DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation(); 104 Document document = domImpl.createDocument("http://www.w3.org/2000/svg", "svg", null); 105 SVGGraphics2D svgGenerator = new SVGGraphics2D(document); 106 svgGenerator.clearRect(rect.x, rect.y, rect.width, rect.height); 107 svgGenerator.setSVGCanvasSize(rect.getSize()); 108 svgGenerator.setClip(rect.x, rect.y, rect.width, rect.height); 109 svgGenerator.translate(-border, -border); 110 Renderer.reRender(svgGenerator, rect, z, 1.0, map, context); 111 svgGenerator.stream(dstdir + "tst_" + z + "-" + xtile + "-" + ytile + ".svg"); 112 } 113 } else { 114 tile(zoom, 1, 0, 0); 115 } 116 } 117 118 static void tile(int zoom, int s, int xn, int yn) throws IOException { 119 int scale = (int) Math.pow(2, zoom - 12); 120 int xdir = (scale * xtile) + xn; 121 int ynam = (scale * ytile) + yn; 80 static void tile(int z, int s, int xn, int yn) throws IOException { 81 int border = (z < 12) ? (256 / (int)(Math.pow(2, (11 - zoom)))) : 256; 82 int scale = (int)Math.pow(2, z - 12); 83 int xdir = (scale > 0) ? (scale * xtile) + xn : xtile; 84 int ynam = (scale > 0) ? (scale * ytile) + yn : ytile; 122 85 BufferedImage img = new BufferedImage(256, 256, BufferedImage.TYPE_INT_ARGB); 123 86 Graphics2D g2 = img.createGraphics(); 124 87 g2.scale(s, s); 125 g2.translate(-( 256+ (xn * 256 / s)), -(256+ (yn * 256 / s)));126 Renderer.reRender(g2, new Rectangle(256, 256), z oom, 1, map, context);88 g2.translate(-(border + (xn * 256 / s)), -(border + (yn * 256 / s))); 89 Renderer.reRender(g2, new Rectangle(256, 256), z, 1.0 * Math.pow(2, (zoom - 12)), map, context); 127 90 ByteArrayOutputStream bos = new ByteArrayOutputStream(); 128 91 ImageIO.write(img, "png", bos); 129 92 if (bos.size() > empty) { 130 String dstnam = dstdir + z oom+ "/" + xdir + "/" + ynam + ".png";93 String dstnam = dstdir + z + "/" + xdir + "/" + ynam + ".png"; 131 94 deletes.remove(dstnam); 132 send.add("put " + dstnam + " tiles/" + z oom+ "/" + xdir + "/" + ynam + ".png");133 File ofile = new File(dstdir + "/" + z oom+ "/" + xdir + "/");95 send.add("put " + dstnam + " tiles/" + z + "/" + xdir + "/" + ynam + ".png"); 96 File ofile = new File(dstdir + "/" + z + "/" + xdir + "/"); 134 97 ofile.mkdirs(); 135 FileOutputStream fos = new FileOutputStream(dstdir + "/" + z oom+ "/" + xdir + "/" + ynam + ".png");98 FileOutputStream fos = new FileOutputStream(dstdir + "/" + z + "/" + xdir + "/" + ynam + ".png"); 136 99 bos.writeTo(fos); 137 100 fos.close(); 138 if (send.size() > 10) {139 PrintWriter writer = new PrintWriter(srcdir + z oom+ "-" + xdir + "-" + ynam + ".send", "UTF-8");101 if (send.size() > 20) { 102 PrintWriter writer = new PrintWriter(srcdir + z + "-" + xdir + "-" + ynam + ".send", "UTF-8"); 140 103 for (String str : send) { 141 104 writer.println(str); … … 145 108 } 146 109 } 147 if ((z oom>= 12) && (zoom< 18) && ((zoom< 16) || (bos.size() > empty))) {110 if ((z >= 12) && (z < 18) && ((z < 16) || (bos.size() > empty))) { 148 111 for (int x = 0; x < 2; x++) { 149 112 for (int y = 0; y < 2; y++) { 150 tile((z oom+ 1), (s * 2), (xn * 2 + x), (yn * 2 + y));113 tile((z + 1), (s * 2), (xn * 2 + x), (yn * 2 + y)); 151 114 } 152 115 } … … 181 144 send = new ArrayList<String>(); 182 145 deletes = new HashMap<String, Boolean>(); 183 BufferedReader in = new BufferedReader(new FileReader(srcdir + zoom + "-" +xtile + "-" + ytile + ".osm"));146 BufferedReader in = new BufferedReader(new FileReader(srcdir + xtile + "-" + ytile + "-" + zoom + ".osm")); 184 147 map = new S57map(true); 185 148 S57osm.OSMmap(in, map, false); 186 149 in.close(); 150 context = new Context(); 151 ByteArrayOutputStream bos = new ByteArrayOutputStream(); 152 ImageIO.write(new BufferedImage(256, 256, BufferedImage.TYPE_INT_ARGB), "png", bos); 153 empty = bos.size(); 187 154 if (zoom == 12) { 188 155 clean(12, 0, 0); 189 156 } 190 tileMap(dstdir, zoom); 191 // if ((send.size() + deletes.size()) > 0) { 192 // PrintWriter writer = new PrintWriter(srcdir + zoom + "-" + xtile + "-" + ytile + ".send", "UTF-8"); 193 // for (String str : send) { 194 // writer.println(str); 195 // } 196 // for (String del : deletes.keySet()) { 197 // writer.println("rm " + del); 198 // } 199 // writer.close(); 200 // } 157 tile(zoom, 1, 0, 0); 158 if (send.size() > 0) { 159 PrintWriter writer = new PrintWriter(srcdir + zoom + "-" + xtile + "-" + ytile + ".send", "UTF-8"); 160 for (String str : send) { 161 writer.println(str); 162 } 163 writer.close(); 164 } 165 if (deletes.size() > 0) { 166 PrintWriter writer = new PrintWriter(srcdir + zoom + "-" + xtile + "-" + ytile + ".delete", "UTF-8"); 167 for (String del : deletes.keySet()) { 168 writer.println("rm " + del); 169 } 170 writer.close(); 171 } 201 172 System.exit(0); 202 173 }
Note:
See TracChangeset
for help on using the changeset viewer.