mil.nga.geopackage.tiles.features.custom.NumberFeaturesTile Java Examples

The following examples show how to use mil.nga.geopackage.tiles.features.custom.NumberFeaturesTile. 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: MapFragment.java    From mage-android with Apache License 2.0 4 votes vote down vote up
/**
 * 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);
}