private static String toHTML(Coordinates c, int zoom) { PUWG92 puwg92 = new PUWG92(c); UTM utm = new UTM(c); LatLon latLon = new LatLon(c); String slatLon = String.format("N %02.08f\u00B0 E %02.08f\u00B0", latLon.getLat(), latLon.getLon()); String slatLonDeg = GeoUtils.getDegMinFormat(latLon.getLat(), true) + " " + GeoUtils.getDegMinFormat(latLon.getLon(), false); CoordinateDms2Format fmt = new CoordinateDms2Format(new DecimalFormatSymbols()); String slatLonSec = "N " + fmt.format(latLon.getLat()) + " E " + fmt.format(latLon.getLon()); String sutm = String.format("%s %.0f E %.0f N", utm.getZone(), utm.getEasting(), utm.getNorthing()); String spuwg = String.format("X %06.0f Y %06.0f", puwg92.getY(), puwg92.getX()); String text = "<html>\n" + slatLon + "<br/>\n" + // slatLonDeg+"<br/>\n"+ // slatLonSec+"<br/>\n"+ spuwg + "<br/>\n" + sutm + "<br/>\n" + zoom + "\n</html>"; return text; }
public void setCenterLocation(double lat, double lon) { breakMapThread = true; useOverlay.tileX = GeoUtils.long2tilex(lon, useOverlay.m_zoom); useOverlay.tileY = GeoUtils.lat2tiley(lat, useOverlay.m_zoom); imgOffsetX += scrWidth / 2.0f; imgOffsetY += scrHeight / 2.0f; restartMap(); }
@Test(dataProvider = "coordinateData") public void convertToEuclidean(Coordinate latLng) throws NoninvertibleTransformException, TransformException { final Coordinate xy = GeoUtils.convertToEuclidean(latLng); final MathTransform transform = GeoUtils.getTransform(latLng); final Coordinate latLngAgain = GeoUtils.convertToLatLon(transform, xy); ArrayAsserts.assertArrayEquals( new double[] {latLng.x, latLng.y}, new double[] {latLngAgain.x, latLngAgain.y}, 1e-4); }
private WayNodePreprocessingResult preprocessWayNodes( TDWay way, boolean waynodeCompression, boolean pixelCompression, boolean polygonClipping, byte maxZoomCurrentInterval, byte minZoomCurrentInterval, TileCoordinate tile) { List<GeoCoordinate> waynodeCoordinates = way.wayNodesAsCoordinateList(); // if the sub file for lower zoom levels is written, remove all way // nodes from the list which are projected on the same pixel if (pixelCompression && maxZoomCurrentInterval <= MAX_ZOOMLEVEL_PIXEL_FILTER) { waynodeCoordinates = GeoUtils.filterWaynodesOnSamePixel( waynodeCoordinates, maxZoomCurrentInterval, PIXEL_COMPRESSION_MAX_DELTA); } // if the way is a multipolygon without a name, clip the way to the // tile if (polygonClipping && way.getWaytype() >= 2 && waynodeCoordinates.size() >= 4 && (way.getName() == null || way.getName().length() == 0) && minZoomCurrentInterval >= MIN_ZOOMLEVEL_POLYGON_CLIPPING) { List<GeoCoordinate> clipped = GeoUtils.clipPolygonToTile(waynodeCoordinates, tile); if (clipped != null) waynodeCoordinates = clipped; } // if the wayNodeCompression flag is set, compress the way nodes // with a minimal amount of bytes List<Integer> waynodesAsList = null; int maxDiff = Integer.MAX_VALUE; if (waynodeCompression) { waynodesAsList = GeoUtils.waynodeAbsoluteCoordinatesToOffsets(waynodeCoordinates); maxDiff = GeoUtils.maxDiffBetweenCompressedWayNodes(waynodesAsList); } else { waynodesAsList = waynodesAsList(waynodeCoordinates); } WayNodePreprocessingResult result = new WayNodePreprocessingResult(waynodesAsList, computeCompressionType(maxDiff)); return result; }
@Override public Short call() { return GeoUtils.computeBitmask(way, baseTile); }
public void run() { int x, y; Bitmap locTile; Canvas canvas; float useLon, useLat, useLonMax, useLatMax; System.gc(); if ((useOverlay.tileX == 0) && (useOverlay.tileY == 0)) return; mapThreadRunning = true; try { if (locMap == null) locMap = Bitmap.createBitmap(tileWidth * 256, tileHeight * 256, Bitmap.Config.ARGB_8888); } catch (OutOfMemoryError oome) { return; } locMap.eraseColor(Color.BLACK); canvas = new Canvas(locMap); useLon = (GeoUtils.tilex2long(useOverlay.tileX, useOverlay.m_zoom) + GeoUtils.tilex2long(useOverlay.tileX + 1, useOverlay.m_zoom)) / 2.0f; useLat = (GeoUtils.tiley2lat(useOverlay.tileY, useOverlay.m_zoom) + GeoUtils.tiley2lat(useOverlay.tileY + 1, useOverlay.m_zoom)) / 2.0f; while (mScaleFactor >= 2.0) { mScaleFactor /= 2.0f; useOverlay.m_zoom++; if (useOverlay.m_zoom > 17) { useOverlay.m_zoom = 17; imgOffsetX -= (scrWidth - (scrWidth * 2.0)) / 2.0; imgOffsetY -= (scrHeight - (scrHeight * 2.0)) / 2.0; } } while (mScaleFactor <= 0.5) { mScaleFactor *= 2.0f; useOverlay.m_zoom--; if (useOverlay.m_zoom < 3) { useOverlay.m_zoom = 3; imgOffsetX -= (scrWidth - (scrWidth * 2.0)) / 2.0; imgOffsetY -= (scrHeight - (scrHeight * 2.0)) / 2.0; } } mScaleFactor = 1.0f; /* if ((wasScaleOp) && (lonCenter!=0.0f) && (latCenter!=0.0f)) { tileX=GeoUtils.long2tilex(lonCenter,m_zoom); tileY=GeoUtils.lat2tiley(latCenter,m_zoom); tileX-=(scrWidth / 256); tileY-=(scrWidth / 256); } else*/ { useOverlay.tileX = GeoUtils.long2tilex(useLon, useOverlay.m_zoom); useOverlay.tileY = GeoUtils.lat2tiley(useLat, useOverlay.m_zoom); } useLon = GeoUtils.tilex2long(useOverlay.tileX - 1, useOverlay.m_zoom); useLat = GeoUtils.tiley2lat(useOverlay.tileY - 1, useOverlay.m_zoom); useLonMax = GeoUtils.tilex2long(useOverlay.tileX + tileWidth + 1, useOverlay.m_zoom); useLatMax = GeoUtils.tiley2lat(useOverlay.tileY + tileHeight + 1, useOverlay.m_zoom); /* if (imgOffsetX>scrWidth) { imgOffsetX=scrWidth/2; } if (imgOffsetX<=-scrWidth) { imgOffsetX=-scrWidth/2; } if (imgOffsetY>scrHeight) { imgOffsetY=scrHeight/2; } if (imgOffsetY<=-scrHeight) { imgOffsetY=-scrHeight/2; }*/ while (imgOffsetX > 0) { imgOffsetX -= 256.0f; useOverlay.tileX--; } while (imgOffsetX <= -256.0) { imgOffsetX += 256.0f; useOverlay.tileX++; } while (imgOffsetY > 0) { imgOffsetY -= 256.0f; useOverlay.tileY--; } while (imgOffsetY <= -256.0) { imgOffsetY += 256.0f; useOverlay.tileY++; } // calculate lat/lon of screen center point /* { int useTileX=tileX,useTileY=tileY; x=(int)((scrWidth/2.0f)+imgOffsetX); y=(int)((scrHeight/2.0f)+imgOffsetY); useTileX+=(x / 256); x=x % 256; useTileY+=(y / 256); y=y % 256; float tileLon1=GeoUtils.tilex2long(useTileX,m_zoom); float tileLat1=GeoUtils.tiley2lat(useTileY,m_zoom); float tileLon2=GeoUtils.tilex2long(useTileX+1,m_zoom); float tileLat2=GeoUtils.tiley2lat(useTileY+1,m_zoom); lonCenter=(((tileLon2-tileLon1)/256.0f)*x)+tileLon1; latCenter=(((tileLat2-tileLat1)/256.0f)*y)+tileLat1; }*/ matrix.setTranslate(imgOffsetX, imgOffsetY); breakMapThread = false; mapThreadRunning = false; for (x = 0; x < tileWidth; x++) for (y = 0; y < tileHeight; y++) { if (breakMapThread) return; locTile = geoUtils.loadMapTile( getContext(), useOverlay.tileX + x, useOverlay.tileY + y, useOverlay.m_zoom, allowNetAccess); if (locTile != null) canvas.drawBitmap(locTile, x * 256, y * 256, null); postInvalidate(); } useOverlay.doDraw(canvas, useLon, useLonMax, useLat, useLatMax, locMap); postInvalidate(); System.gc(); }