mil.nga.geopackage.tiles.features.FeatureTiles Java Examples
The following examples show how to use
mil.nga.geopackage.tiles.features.FeatureTiles.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FeatureOverlayQuery.java From geopackage-android-map with MIT License | 6 votes |
/** * Constructor * * @param context context * @param boundedOverlay bounded overlay * @param featureTiles feature tiles * @since 1.2.5 */ public FeatureOverlayQuery(Context context, BoundedOverlay boundedOverlay, FeatureTiles featureTiles) { this.boundedOverlay = boundedOverlay; this.featureTiles = featureTiles; Resources resources = context.getResources(); // Get the screen percentage to determine when a feature is clicked TypedValue screenPercentage = new TypedValue(); resources.getValue(R.dimen.map_feature_overlay_click_screen_percentage, screenPercentage, true); screenClickPercentage = screenPercentage.getFloat(); maxFeaturesInfo = resources.getBoolean(R.bool.map_feature_overlay_max_features_info); featuresInfo = resources.getBoolean(R.bool.map_feature_overlay_features_info); FeatureDao featureDao = featureTiles.getFeatureDao(); featureInfoBuilder = new FeatureInfoBuilder(context, featureDao); }
Example #2
Source File: FeatureTilesTest.java From geopackage-android with MIT License | 6 votes |
private void createTiles(FeatureTiles featureTiles, int zoom) { int tilesPerSide = TileBoundingBoxUtils.tilesPerSide(zoom); for (int i = 0; i < tilesPerSide; i++) { for (int j = 0; j < tilesPerSide; j++) { Bitmap bitmap = featureTiles.drawTile(i, j, zoom); if (bitmap != null) { long count = featureTiles.queryIndexedFeaturesCount(i, j, zoom); assertTrue(count > 0); assertEquals(featureTiles.getTileWidth(), bitmap.getWidth()); assertEquals(featureTiles.getTileHeight(), bitmap.getHeight()); } } } }
Example #3
Source File: FeatureTilesTest.java From geopackage-java with MIT License | 6 votes |
private void createTiles(FeatureTiles featureTiles, int zoom) { int tilesPerSide = TileBoundingBoxUtils.tilesPerSide(zoom); for (int i = 0; i < tilesPerSide; i++) { for (int j = 0; j < tilesPerSide; j++) { BufferedImage image = featureTiles.drawTile(i, j, zoom); if (image != null) { long count = featureTiles.queryIndexedFeaturesCount(i, j, zoom); TestCase.assertTrue(count > 0); TestCase.assertEquals(featureTiles.getTileWidth(), image.getWidth()); TestCase.assertEquals(featureTiles.getTileHeight(), image.getHeight()); } } } }
Example #4
Source File: FeatureTileUtils.java From geopackage-java with MIT License | 5 votes |
/** * Create a new feature tiles * * @param geoPackage * @param featureDao * @param useIcon * true to use an icon instead of the default point * @return feature tiles */ public static FeatureTiles createFeatureTiles(GeoPackage geoPackage, FeatureDao featureDao, boolean useIcon) { FeatureTiles featureTiles = new DefaultFeatureTiles(featureDao); if (useIcon) { BufferedImage icon = new BufferedImage(5, 5, BufferedImage.TYPE_INT_ARGB); Graphics2D graphics = icon.createGraphics(); graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); graphics.setColor(Color.MAGENTA); graphics.fillRect(0, 0, 5, 5); FeatureTilePointIcon pointIcon = new FeatureTilePointIcon(icon); pointIcon.centerIcon(); featureTiles.setPointIcon(pointIcon); } else { featureTiles.setPointColor(Color.BLUE); } featureTiles.setLineColor(Color.GREEN); featureTiles.setPolygonColor(Color.RED); featureTiles.setFillPolygon(true); featureTiles.setPolygonFillColor(new Color(255, 0, 0, 50)); featureTiles.calculateDrawOverlap(); return featureTiles; }
Example #5
Source File: GeoPackageExample.java From geopackage-android with MIT License | 5 votes |
private static void createFeatureTileLinkExtension(Context context, GeoPackage geoPackage) throws SQLException, IOException { List<String> featureTables = geoPackage.getFeatureTables(); for (String featureTable : featureTables) { FeatureDao featureDao = geoPackage.getFeatureDao(featureTable); FeatureTiles featureTiles = new DefaultFeatureTiles(context, geoPackage, featureDao, context.getResources().getDisplayMetrics().density); BoundingBox boundingBox = featureDao.getBoundingBox(); Projection projection = featureDao.getProjection(); Projection requestProjection = ProjectionFactory .getProjection(ProjectionConstants.EPSG_WEB_MERCATOR); ProjectionTransform transform = projection .getTransformation(requestProjection); BoundingBox requestBoundingBox = boundingBox.transform(transform); int zoomLevel = TileBoundingBoxUtils .getZoomLevel(requestBoundingBox); zoomLevel = Math.max(zoomLevel, 8); zoomLevel = Math.min(zoomLevel, 19); int minZoom = zoomLevel - 8; int maxZoom = zoomLevel + 2; TileGenerator tileGenerator = new FeatureTileGenerator(context, geoPackage, featureTable + "_tiles", featureTiles, minZoom, maxZoom, requestBoundingBox, requestProjection); tileGenerator.generateTiles(); featureTiles.close(); } }
Example #6
Source File: FeatureTilesTest.java From geopackage-android with MIT License | 5 votes |
/** * Test feature tiles * * @throws java.sql.SQLException */ public void testFeatureTiles(boolean useIcon) throws SQLException { FeatureDao featureDao = FeatureTileUtils.createFeatureDao(geoPackage); int num = FeatureTileUtils.insertFeatures(geoPackage, featureDao); FeatureTiles featureTiles = FeatureTileUtils.createFeatureTiles(activity, geoPackage, featureDao, useIcon); try { FeatureIndexer indexer = new FeatureIndexer(activity, featureDao); try { indexer.index(); } finally { indexer.close(); } FeatureIndexManager indexManager = new FeatureIndexManager(activity, geoPackage, featureDao); featureTiles.setIndexManager(indexManager); indexManager.setIndexLocation(FeatureIndexType.GEOPACKAGE); int indexed = indexManager.index(); assertEquals(num, indexed); createTiles(featureTiles, 0, 3); } finally { featureTiles.close(); } }
Example #7
Source File: FeatureTileUtils.java From geopackage-android with MIT License | 5 votes |
/** * Create a new feature tiles * * @return */ public static FeatureTiles createFeatureTiles(Context context, GeoPackage geoPackage, FeatureDao featureDao, boolean useIcon) { FeatureTiles featureTiles = new DefaultFeatureTiles(context, featureDao, context.getResources().getDisplayMetrics().density); Paint pointPaint = featureTiles.getPointPaint(); if (useIcon) { Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), mil.nga.geopackage.test.R.drawable.ic_launcher); bitmap = Bitmap.createScaledBitmap(bitmap, 25, 25, false); FeatureTilePointIcon icon = new FeatureTilePointIcon(bitmap); featureTiles.setPointIcon(icon); } else { pointPaint.setColor(Color.BLUE); } Paint linePaint = featureTiles.getLinePaintCopy(); linePaint.setColor(Color.GREEN); featureTiles.setLinePaint(linePaint); Paint polygonPaint = featureTiles.getPolygonPaintCopy(); polygonPaint.setColor(Color.RED); featureTiles.setPolygonPaint(polygonPaint); featureTiles.setFillPolygon(true); Paint polygonFillPaint = featureTiles.getPolygonFillPaintCopy(); polygonFillPaint.setColor(Color.RED); polygonFillPaint.setAlpha(50); featureTiles.setPolygonFillPaint(polygonFillPaint); featureTiles.calculateDrawOverlap(); return featureTiles; }
Example #8
Source File: GeoPackageUtils.java From geopackage-mapcache-android with MIT License | 5 votes |
/** * Prepare the provided feature tiles * * @param featureTiles */ public static void prepareFeatureTiles(FeatureTiles featureTiles) { // TODO The projection for 27700 returns different values when going to and from web mercator // Buffer the pixels around the image when querying the feature index if (featureTiles.getFeatureDao().getProjection().equals(ProjectionConstants.AUTHORITY_EPSG, 27700)) { featureTiles.setHeightDrawOverlap(featureTiles.getHeightDrawOverlap() + 100); } }
Example #9
Source File: GeoPackageExample.java From geopackage-java with MIT License | 5 votes |
private static void createFeatureTileLinkExtension(GeoPackage geoPackage) throws SQLException, IOException { List<String> featureTables = geoPackage.getFeatureTables(); for (String featureTable : featureTables) { FeatureDao featureDao = geoPackage.getFeatureDao(featureTable); FeatureTiles featureTiles = new DefaultFeatureTiles(geoPackage, featureDao); BoundingBox boundingBox = featureDao.getBoundingBox(); Projection projection = featureDao.getProjection(); Projection requestProjection = ProjectionFactory .getProjection(ProjectionConstants.EPSG_WEB_MERCATOR); ProjectionTransform transform = projection .getTransformation(requestProjection); BoundingBox requestBoundingBox = boundingBox.transform(transform); int zoomLevel = TileBoundingBoxUtils .getZoomLevel(requestBoundingBox); zoomLevel = Math.max(zoomLevel, 8); zoomLevel = Math.min(zoomLevel, 19); int minZoom = zoomLevel - 8; int maxZoom = zoomLevel + 2; TileGenerator tileGenerator = new FeatureTileGenerator(geoPackage, featureTable + "_tiles", featureTiles, minZoom, maxZoom, requestBoundingBox, requestProjection); tileGenerator.generateTiles(); } }
Example #10
Source File: MapFragment.java From mage-android with Apache License 2.0 | 4 votes |
/** * Add the GeoPackage Feature Table Cache Overlay * @param enabledCacheOverlays * @param featureTableCacheOverlay * @param geoPackage */ private void addGeoPackageFeatureCacheOverlay(Map<String, CacheOverlay> enabledCacheOverlays, GeoPackageFeatureTableCacheOverlay featureTableCacheOverlay, GeoPackage geoPackage){ // Retrieve the cache overlay if it already exists (and remove from cache overlays) CacheOverlay cacheOverlay = cacheOverlays.remove(featureTableCacheOverlay.getCacheName()); if(cacheOverlay != null){ // If the existing cache overlay is being replaced, create a new cache overlay if(featureTableCacheOverlay.getParent().isAdded()){ cacheOverlay = null; } for(GeoPackageTileTableCacheOverlay linkedTileTable: featureTableCacheOverlay.getLinkedTileTables()){ cacheOverlays.remove(linkedTileTable.getCacheName()); } } if(cacheOverlay == null) { // Add the features to the map FeatureDao featureDao = geoPackage.getFeatureDao(featureTableCacheOverlay.getName()); // If indexed, add as a tile overlay if(featureTableCacheOverlay.isIndexed()){ FeatureTiles featureTiles = new DefaultFeatureTiles(getActivity(), geoPackage, featureDao, getResources().getDisplayMetrics().density); Integer maxFeaturesPerTile = null; if(featureDao.getGeometryType() == GeometryType.POINT){ maxFeaturesPerTile = getResources().getInteger(R.integer.geopackage_feature_tiles_max_points_per_tile); }else{ maxFeaturesPerTile = getResources().getInteger(R.integer.geopackage_feature_tiles_max_features_per_tile); } featureTiles.setMaxFeaturesPerTile(maxFeaturesPerTile); NumberFeaturesTile numberFeaturesTile = new NumberFeaturesTile(getActivity()); // Adjust the max features number tile draw paint attributes here as needed to // change how tiles are drawn when more than the max features exist in a tile featureTiles.setMaxFeaturesTileDraw(numberFeaturesTile); // Adjust the feature tiles draw paint attributes here as needed to change how // features are drawn on tiles FeatureOverlay featureOverlay = new FeatureOverlay(featureTiles); featureOverlay.setMinZoom(featureTableCacheOverlay.getMinZoom()); // Get the tile linked overlay BoundedOverlay overlay = GeoPackageOverlayFactory.getLinkedFeatureOverlay(featureOverlay, geoPackage); FeatureOverlayQuery featureOverlayQuery = new FeatureOverlayQuery(getActivity(), overlay, featureTiles); featureTableCacheOverlay.setFeatureOverlayQuery(featureOverlayQuery); TileOverlayOptions overlayOptions = createFeatureTileOverlayOptions(overlay); TileOverlay tileOverlay = map.addTileOverlay(overlayOptions); featureTableCacheOverlay.setTileOverlay(tileOverlay); } // Not indexed, add the features to the map else { int maxFeaturesPerTable = 0; if(featureDao.getGeometryType() == GeometryType.POINT){ maxFeaturesPerTable = getResources().getInteger(R.integer.geopackage_features_max_points_per_table); }else{ maxFeaturesPerTable = getResources().getInteger(R.integer.geopackage_features_max_features_per_table); } Projection projection = featureDao.getProjection(); GoogleMapShapeConverter shapeConverter = new GoogleMapShapeConverter(projection); FeatureCursor featureCursor = featureDao.queryForAll(); try { final int totalCount = featureCursor.getCount(); int count = 0; while (featureCursor.moveToNext()) { try { FeatureRow featureRow = featureCursor.getRow(); GeoPackageGeometryData geometryData = featureRow.getGeometry(); if (geometryData != null && !geometryData.isEmpty()) { Geometry geometry = geometryData.getGeometry(); if (geometry != null) { GoogleMapShape shape = shapeConverter.toShape(geometry); // Set the Shape Marker, PolylineOptions, and PolygonOptions here if needed to change color and style featureTableCacheOverlay.addShapeToMap(featureRow.getId(), shape, map); if (++count >= maxFeaturesPerTable) { if (count < totalCount) { Toast.makeText(getActivity().getApplicationContext(), featureTableCacheOverlay.getCacheName() + "- added " + count + " of " + totalCount, Toast.LENGTH_LONG).show(); } break; } } } }catch(Exception e){ Log.e(LOG_NAME, "Failed to display feature. GeoPackage: " + geoPackage.getName() + ", Table: " + featureDao.getTableName() + ", Row: " + featureCursor.getPosition(), e); } } } finally { featureCursor.close(); } } cacheOverlay = featureTableCacheOverlay; } // Add the cache overlay to the enabled cache overlays enabledCacheOverlays.put(cacheOverlay.getCacheName(), cacheOverlay); }
Example #11
Source File: GeoPackageFeatureTileProvider.java From osmdroid with Apache License 2.0 | 4 votes |
public void set(int minZoom, FeatureTiles featureTiles) { this.featureTiles = featureTiles; minzoom = minZoom; }
Example #12
Source File: FeaturePreviewUtils.java From geopackage-java with MIT License | 4 votes |
/** * Test the GeoPackage draw feature preview * * @param geoPackage * GeoPackage * @throws IOException * upon error */ public static void testDraw(GeoPackage geoPackage) throws IOException { for (String featureTable : geoPackage.getFeatureTables()) { FeatureDao featureDao = geoPackage.getFeatureDao(featureTable); int count = featureDao.count( CoreSQLUtils.quoteWrap(featureDao.getGeometryColumnName()) + " IS NOT NULL"); BoundingBox contentsBoundingBox = geoPackage .getContentsBoundingBox(featureTable); BoundingBox indexedBoundingBox = geoPackage .getBoundingBox(featureTable); boolean expectImage = (contentsBoundingBox != null || indexedBoundingBox != null) && count > 0; boolean epsg = featureDao.getProjection().getAuthority() .equalsIgnoreCase(ProjectionConstants.AUTHORITY_EPSG); FeaturePreview preview = new FeaturePreview(geoPackage, featureDao); BufferedImage image = preview.draw(); if (epsg) { assertEquals(expectImage, image != null); } if (writeImages) { ImageIO.write(image, "png", new File("image.png")); } preview.setBufferPercentage(0.4); preview.setLimit((int) Math.ceil(count / 2.0)); BufferedImage imageLimit = preview.draw(); if (epsg) { assertEquals(expectImage, imageLimit != null); } if (writeImages) { ImageIO.write(imageLimit, "png", new File("image_limit.png")); } preview.setManual(true); preview.setBufferPercentage(0.05); preview.setLimit(null); FeatureTiles featureTiles = preview.getFeatureTiles(); featureTiles.setTileWidth(TileUtils.TILE_PIXELS_DEFAULT); featureTiles.setTileHeight(TileUtils.TILE_PIXELS_DEFAULT); featureTiles.setScale( TileUtils.tileScale(TileUtils.TILE_PIXELS_DEFAULT)); featureTiles.clearIconCache(); BufferedImage imageManual = preview.draw(); if (epsg) { assertNotNull(imageManual); } if (writeImages) { ImageIO.write(imageManual, "png", new File("image_manual.png")); } preview.setBufferPercentage(0.35); preview.setLimit(Math.max(count - 1, 1)); BufferedImage imageManualLimit = preview.draw(); if (epsg) { assertNotNull(imageManualLimit); } if (writeImages) { ImageIO.write(imageManualLimit, "png", new File("image_manual_limit.png")); } preview.setBufferPercentage(0.15); preview.setLimit(null); preview.appendWhere( CoreSQLUtils.quoteWrap(featureDao.getIdColumnName()) + " > " + ((int) Math.floor(count / 2.0))); BufferedImage imageManualWhere = preview.draw(); if (epsg) { assertNotNull(imageManualWhere); } if (writeImages) { ImageIO.write(imageManualWhere, "png", new File("image_manual_where.png")); System.out.println("Breakpoint here"); } } }
Example #13
Source File: FeatureTilesTest.java From geopackage-java with MIT License | 4 votes |
private void createTiles(FeatureTiles featureTiles, int minZoom, int maxZoom) { for (int i = minZoom; i <= maxZoom; i++) { createTiles(featureTiles, i); } }
Example #14
Source File: FeatureTilesTest.java From geopackage-java with MIT License | 4 votes |
/** * Test feature tiles * * @param useIcon * * @throws java.sql.SQLException */ public void testFeatureTiles(boolean useIcon) throws SQLException { FeatureDao featureDao = FeatureTileUtils.createFeatureDao(geoPackage); int num = FeatureTileUtils.insertFeatures(geoPackage, featureDao); FeatureTiles featureTiles = FeatureTileUtils.createFeatureTiles( geoPackage, featureDao, useIcon); FeatureTableIndex featureIndex = new FeatureTableIndex(geoPackage, featureDao); int indexed = featureIndex.index(); TestCase.assertEquals(num, indexed); featureTiles.setFeatureIndex(featureIndex); createTiles(featureTiles, 0, 3); }
Example #15
Source File: LoadTilesTask.java From geopackage-mapcache-android with MIT License | 4 votes |
/** * Load tiles from features * * @param activity * @param callback * @param active * @param geoPackage * @param tableName * @param featureTiles * @param minZoom * @param maxZoom * @param compressFormat * @param compressQuality * @param googleTiles * @param boundingBox * @param scaling * @param authority * @param code */ public static void loadTiles(Activity activity, ILoadTilesTask callback, GeoPackageDatabases active, GeoPackage geoPackage, String tableName, FeatureTiles featureTiles, int minZoom, int maxZoom, CompressFormat compressFormat, Integer compressQuality, boolean googleTiles, BoundingBox boundingBox, TileScaling scaling, String authority, String code) { GeoPackageUtils.prepareFeatureTiles(featureTiles); Projection projection = ProjectionFactory.getProjection(authority, code); BoundingBox bbox = transform(boundingBox, projection); TileGenerator tileGenerator = new FeatureTileGenerator(activity, geoPackage, tableName, featureTiles, minZoom, maxZoom, bbox, projection); setTileGenerator(activity, tileGenerator, minZoom, maxZoom, compressFormat, compressQuality, googleTiles, boundingBox, scaling); loadTiles(activity, callback, active, geoPackage, tableName, tileGenerator); }
Example #16
Source File: GeoPackageUtils.java From geopackage-mapcache-android with MIT License | 4 votes |
/** * Prepare the feature draw limits and defaults * * @param context * @param geoPackage * @param featureTable * @param pointAlpha * @param lineAlpha * @param polygonAlpha * @param polygonFillAlpha * @param pointColor * @param lineColor * @param pointRadius * @param lineStroke * @param polygonColor * @param polygonStroke * @param polygonFill * @param polygonFillColor */ public static void prepareFeatureDraw(Context context, GeoPackage geoPackage, String featureTable, EditText pointAlpha, EditText lineAlpha, EditText polygonAlpha, EditText polygonFillAlpha, EditText pointColor, EditText lineColor, EditText pointRadius, EditText lineStroke, EditText polygonColor, EditText polygonStroke, CheckBox polygonFill, EditText polygonFillColor) { FeatureTableStyles featureTableStyles = new FeatureTableStyles(geoPackage, featureTable); // Set feature limits pointAlpha.setFilters(new InputFilter[]{new InputFilterMinMax( 0, 255)}); lineAlpha.setFilters(new InputFilter[]{new InputFilterMinMax( 0, 255)}); polygonAlpha.setFilters(new InputFilter[]{new InputFilterMinMax( 0, 255)}); polygonFillAlpha.setFilters(new InputFilter[]{new InputFilterMinMax( 0, 255)}); // Set default feature attributes FeatureTiles featureTiles = new DefaultFeatureTiles(context); String defaultColor = "#000000"; StyleRow pointStyle = featureTableStyles.getTableStyle(GeometryType.POINT); if(pointStyle != null){ mil.nga.geopackage.style.Color pointStyleColor = pointStyle.getColorOrDefault(); pointColor.setText(pointStyleColor.getColorHex()); pointAlpha.setText(String.valueOf(pointStyleColor.getAlpha())); pointRadius.setText(new DecimalFormat("0.0#").format(pointStyle.getWidthOrDefault() / 2.0)); }else{ Paint pointPaint = featureTiles.getPointPaint(); pointColor.setText(defaultColor); pointAlpha.setText(String.valueOf(pointPaint.getAlpha())); pointRadius.setText(String.valueOf(featureTiles.getPointRadius())); } StyleRow lineStyle = featureTableStyles.getTableStyle(GeometryType.LINESTRING); if(lineStyle != null){ mil.nga.geopackage.style.Color lineStyleColor = lineStyle.getColorOrDefault(); lineColor.setText(lineStyleColor.getColorHex()); lineAlpha.setText(String.valueOf(lineStyleColor.getAlpha())); lineStroke.setText(new DecimalFormat("0.0#").format(lineStyle.getWidthOrDefault())); }else{ Paint linePaint = featureTiles.getLinePaintCopy(); lineColor.setText(defaultColor); lineAlpha.setText(String.valueOf(linePaint.getAlpha())); lineStroke.setText(String.valueOf(linePaint.getStrokeWidth())); } StyleRow polygonStyle = featureTableStyles.getTableStyle(GeometryType.POLYGON); if(polygonStyle != null){ mil.nga.geopackage.style.Color polygonStyleColor = polygonStyle.getColorOrDefault(); polygonColor.setText(polygonStyleColor.getColorHex()); polygonAlpha.setText(String.valueOf(polygonStyleColor.getAlpha())); polygonStroke.setText(new DecimalFormat("0.0#").format(polygonStyle.getWidthOrDefault())); mil.nga.geopackage.style.Color polygonStyleFillColor = polygonStyle.getFillColor(); polygonFill.setChecked(polygonStyleFillColor != null); if(polygonStyleFillColor != null){ polygonFillColor.setText(polygonStyleFillColor.getColorHex()); polygonFillAlpha.setText(String.valueOf(polygonStyleFillColor.getAlpha())); }else{ polygonFillColor.setText(defaultColor); polygonFillAlpha.setText(String.valueOf(255)); } }else{ Paint polygonPaint = featureTiles.getPolygonPaintCopy(); polygonColor.setText(defaultColor); polygonAlpha.setText(String.valueOf(polygonPaint.getAlpha())); polygonStroke.setText(String.valueOf(polygonPaint.getStrokeWidth())); polygonFill.setChecked(featureTiles.isFillPolygon()); Paint polygonFillPaint = featureTiles.getPolygonFillPaintCopy(); polygonFillColor.setText(defaultColor); polygonFillAlpha.setText(String.valueOf(polygonFillPaint.getAlpha())); } }
Example #17
Source File: MapFragment.java From mage-android with Apache License 2.0 | 4 votes |
/** * Add the GeoPackage Tile Table Cache Overlay * @param enabledCacheOverlays * @param tileTableCacheOverlay * @param geoPackage * @param linkedToFeatures */ private void addGeoPackageTileCacheOverlay(Map<String, CacheOverlay> enabledCacheOverlays, GeoPackageTileTableCacheOverlay tileTableCacheOverlay, GeoPackage geoPackage, boolean linkedToFeatures){ // Retrieve the cache overlay if it already exists (and remove from cache overlays) CacheOverlay cacheOverlay = cacheOverlays.remove(tileTableCacheOverlay.getCacheName()); if(cacheOverlay != null){ // If the existing cache overlay is being replaced, create a new cache overlay if(tileTableCacheOverlay.getParent().isAdded()){ cacheOverlay = null; } } if(cacheOverlay == null){ // Create a new GeoPackage tile provider and add to the map TileDao tileDao = geoPackage.getTileDao(tileTableCacheOverlay.getName()); TileTableScaling tileTableScaling = new TileTableScaling(geoPackage, tileDao); TileScaling tileScaling = tileTableScaling.get(); BoundedOverlay overlay = GeoPackageOverlayFactory .getBoundedOverlay(tileDao, getResources().getDisplayMetrics().density, tileScaling); TileOverlayOptions overlayOptions = null; if(linkedToFeatures){ overlayOptions = createFeatureTileOverlayOptions(overlay); }else { overlayOptions = createTileOverlayOptions(overlay); } TileOverlay tileOverlay = map.addTileOverlay(overlayOptions); tileTableCacheOverlay.setTileOverlay(tileOverlay); // Check for linked feature tables tileTableCacheOverlay.clearFeatureOverlayQueries(); FeatureTileTableLinker linker = new FeatureTileTableLinker(geoPackage); List<FeatureDao> featureDaos = linker.getFeatureDaosForTileTable(tileDao.getTableName()); for(FeatureDao featureDao: featureDaos){ // Create the feature tiles FeatureTiles featureTiles = new DefaultFeatureTiles(getActivity(), geoPackage, featureDao, getResources().getDisplayMetrics().density); // Add the feature overlay query FeatureOverlayQuery featureOverlayQuery = new FeatureOverlayQuery(getActivity(), overlay, featureTiles); tileTableCacheOverlay.addFeatureOverlayQuery(featureOverlayQuery); } cacheOverlay = tileTableCacheOverlay; } // Add the cache overlay to the enabled cache overlays enabledCacheOverlays.put(cacheOverlay.getCacheName(), cacheOverlay); }
Example #18
Source File: FeaturePreviewUtils.java From geopackage-android with MIT License | 4 votes |
/** * Test the GeoPackage draw feature preview * * @param activity activity * @param geoPackage GeoPackage * @throws IOException upon error */ public static void testDraw(Activity activity, GeoPackage geoPackage) throws IOException { for (String featureTable : geoPackage.getFeatureTables()) { FeatureDao featureDao = geoPackage.getFeatureDao(featureTable); int count = featureDao.count( CoreSQLUtils.quoteWrap(featureDao.getGeometryColumnName()) + " IS NOT NULL"); BoundingBox contentsBoundingBox = geoPackage .getContentsBoundingBox(featureTable); BoundingBox indexedBoundingBox = geoPackage .getBoundingBox(featureTable); boolean expectImage = (contentsBoundingBox != null || indexedBoundingBox != null) && count > 0; boolean epsg = featureDao.getProjection().getAuthority() .equalsIgnoreCase(ProjectionConstants.AUTHORITY_EPSG); FeaturePreview preview = new FeaturePreview(activity, geoPackage, featureDao); Bitmap image = preview.draw(); if (epsg) { assertEquals(expectImage, image != null); } preview.setBufferPercentage(0.4); preview.setLimit((int) Math.ceil(count / 2.0)); Bitmap imageLimit = preview.draw(); if (epsg) { assertEquals(expectImage, imageLimit != null); } preview.setManual(true); preview.setBufferPercentage(0.05); preview.setLimit(null); FeatureTiles featureTiles = preview.getFeatureTiles(); featureTiles.setTileWidth(TileUtils.TILE_PIXELS_DEFAULT); featureTiles.setTileHeight(TileUtils.TILE_PIXELS_DEFAULT); featureTiles.setDensity( TileUtils.density(TileUtils.TILE_PIXELS_DEFAULT)); featureTiles.clearIconCache(); Bitmap imageManual = preview.draw(); if (epsg) { assertNotNull(imageManual); } preview.setBufferPercentage(0.35); preview.setLimit(Math.max(count - 1, 1)); Bitmap imageManualLimit = preview.draw(); if (epsg) { assertNotNull(imageManualLimit); } preview.setBufferPercentage(0.15); preview.setLimit(null); preview.appendWhere( CoreSQLUtils.quoteWrap(featureDao.getIdColumnName()) + " > " + ((int) Math.floor(count / 2.0))); Bitmap imageManualWhere = preview.draw(); if (epsg) { assertNotNull(imageManualWhere); } if(image != null) { image.recycle(); } if(imageLimit != null) { imageLimit.recycle(); } if(imageManual != null) { imageManual.recycle(); } if(imageManualLimit != null) { imageManualLimit.recycle(); } if(imageManualWhere != null) { imageManualWhere.recycle(); } preview.close(); } }
Example #19
Source File: FeatureTilesTest.java From geopackage-android with MIT License | 4 votes |
private void createTiles(FeatureTiles featureTiles, int minZoom, int maxZoom) { for (int i = minZoom; i <= maxZoom; i++) { createTiles(featureTiles, i); } }
Example #20
Source File: FeatureOverlay.java From geopackage-android-map with MIT License | 2 votes |
/** * Constructor * * @param featureTiles feature tiles */ public FeatureOverlay(FeatureTiles featureTiles) { this.featureTiles = featureTiles; }
Example #21
Source File: FeatureOverlayQuery.java From geopackage-android-map with MIT License | 2 votes |
/** * Get the feature tiles * * @return feature tiles */ public FeatureTiles getFeatureTiles() { return featureTiles; }
Example #22
Source File: FeatureOverlay.java From geopackage-android-map with MIT License | 2 votes |
/** * Get the feature tiles * * @return feature tiles * @since 1.1.0 */ public FeatureTiles getFeatureTiles() { return featureTiles; }