com.google.android.gms.maps.model.TileOverlay Java Examples

The following examples show how to use com.google.android.gms.maps.model.TileOverlay. 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 6 votes vote down vote up
/**
 * Add XYZ Directory tile cache overlay
 * @param enabledCacheOverlays
 * @param xyzDirectoryCacheOverlay
 */
private void addXYZDirectoryCacheOverlay(Map<String, CacheOverlay> enabledCacheOverlays, XYZDirectoryCacheOverlay xyzDirectoryCacheOverlay){
	// Retrieve the cache overlay if it already exists (and remove from cache overlays)
	CacheOverlay cacheOverlay = cacheOverlays.remove(xyzDirectoryCacheOverlay.getCacheName());
	if(cacheOverlay == null){
		// Create a new tile provider and add to the map
		TileProvider tileProvider = new FileSystemTileProvider(256, 256, xyzDirectoryCacheOverlay.getDirectory().getAbsolutePath());
		TileOverlayOptions overlayOptions = createTileOverlayOptions(tileProvider);
		// Set the tile overlay in the cache overlay
		TileOverlay tileOverlay = map.addTileOverlay(overlayOptions);
		xyzDirectoryCacheOverlay.setTileOverlay(tileOverlay);
		cacheOverlay = xyzDirectoryCacheOverlay;
	}
	// Add the cache overlay to the enabled cache overlays
	enabledCacheOverlays.put(cacheOverlay.getCacheName(), cacheOverlay);
}
 
Example #2
Source File: HeatmapsPlacesDemoActivity.java    From android-maps-utils with Apache License 2.0 6 votes vote down vote up
/**
 * Creates check box for a given search term
 *
 * @param keyword the search terms associated with the check box
 */
private void makeCheckBox(final String keyword) {
    mCheckboxLayout.setVisibility(View.VISIBLE);

    // Make new checkbox
    CheckBox checkBox = new CheckBox(this);
    checkBox.setText(keyword);
    checkBox.setTextColor(HEATMAP_COLORS[mOverlaysRendered]);
    checkBox.setChecked(true);
    checkBox.setOnClickListener(view -> {
        CheckBox c = (CheckBox) view;
        // Text is the keyword
        TileOverlay overlay = mOverlays.get(keyword);
        if (overlay != null) {
            overlay.setVisible(c.isChecked());
        }
    });
    mCheckboxLayout.addView(checkBox);
}
 
Example #3
Source File: MapFragment.java    From mage-android with Apache License 2.0 5 votes vote down vote up
private void addURLCacheOverlay(Map<String, CacheOverlay> enabledCacheOverlays, URLCacheOverlay urlCacheOverlay){
       // Retrieve the cache overlay if it already exists (and remove from cache overlays)
	CacheOverlay cacheOverlay = cacheOverlays.remove(urlCacheOverlay.getCacheName());
	if(cacheOverlay == null){
		// Create a new tile provider and add to the map
		TileProvider tileProvider = null;
		boolean isTransparent = false;
		if(urlCacheOverlay.getFormat().equalsIgnoreCase("xyz")) {
			tileProvider = new XYZTileProvider(256, 256, urlCacheOverlay);
		}else if(urlCacheOverlay.getFormat().equalsIgnoreCase("tms")){
			tileProvider = new TMSTileProvider(256, 256, urlCacheOverlay);
		}else {
			tileProvider = new WMSTileProvider(256, 256, urlCacheOverlay);
			WMSCacheOverlay wms = (WMSCacheOverlay)urlCacheOverlay;
			isTransparent =  Boolean.parseBoolean(wms.getWmsTransparent());
		}
		TileOverlayOptions overlayOptions = createTileOverlayOptions(tileProvider);

		if(urlCacheOverlay.isBase()) {
			overlayOptions.zIndex(-4);
		} else if(!isTransparent) {
			overlayOptions.zIndex(-3);
		} else{
			overlayOptions.zIndex(-2);
		}
		// Set the tile overlay in the cache overlay
		TileOverlay tileOverlay = map.addTileOverlay(overlayOptions);
		urlCacheOverlay.setTileOverlay(tileOverlay);
		cacheOverlay = urlCacheOverlay;
	}
	// Add the cache overlay to the enabled cache overlays
	enabledCacheOverlays.put(cacheOverlay.getCacheName(), cacheOverlay);
}
 
Example #4
Source File: MapFragment.java    From mage-android with Apache License 2.0 4 votes vote down vote up
/**
 * 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 #5
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);
}
 
Example #6
Source File: RMBTMapFragment.java    From open-rmbt with Apache License 2.0 4 votes vote down vote up
public TileOverlayHolder(final TileOverlay tileOverlay, final MapOverlayType overlayType) {
	this.tileOverlay = tileOverlay;
	this.overlayType = overlayType;
}
 
Example #7
Source File: RMBTMapFragment.java    From open-rmbt with Apache License 2.0 4 votes vote down vote up
public TileOverlay getTileOverlay() {
	return tileOverlay;
}
 
Example #8
Source File: GeoPackageTileTableCacheOverlay.java    From mage-android with Apache License 2.0 2 votes vote down vote up
/**
 * Get the tile overlay
 *
 * @return
 */
public TileOverlay getTileOverlay() {
    return tileOverlay;
}
 
Example #9
Source File: GeoPackageTileTableCacheOverlay.java    From mage-android with Apache License 2.0 2 votes vote down vote up
/**
 * Set the tile overlay
 *
 * @param tileOverlay
 */
public void setTileOverlay(TileOverlay tileOverlay) {
    this.tileOverlay = tileOverlay;
}
 
Example #10
Source File: GeoPackageFeatureTableCacheOverlay.java    From mage-android with Apache License 2.0 2 votes vote down vote up
/**
 * Get the tile overlay
 *
 * @return tile overlay or null
 */
public TileOverlay getTileOverlay() {
    return tileOverlay;
}
 
Example #11
Source File: GeoPackageFeatureTableCacheOverlay.java    From mage-android with Apache License 2.0 2 votes vote down vote up
/**
 * Set the tile overlay
 *
 * @param tileOverlay
 */
public void setTileOverlay(TileOverlay tileOverlay) {
    this.tileOverlay = tileOverlay;
}
 
Example #12
Source File: XYZDirectoryCacheOverlay.java    From mage-android with Apache License 2.0 2 votes vote down vote up
/**
 * Get the tile overlay
 *
 * @return
 */
public TileOverlay getTileOverlay() {
    return tileOverlay;
}
 
Example #13
Source File: XYZDirectoryCacheOverlay.java    From mage-android with Apache License 2.0 2 votes vote down vote up
/**
 * Set the tile overlay
 *
 * @param tileOverlay
 */
public void setTileOverlay(TileOverlay tileOverlay) {
    this.tileOverlay = tileOverlay;
}
 
Example #14
Source File: URLCacheOverlay.java    From mage-android with Apache License 2.0 2 votes vote down vote up
/**
 * Get the tile overlay
 *
 * @return
 */
public synchronized TileOverlay getTileOverlay() {
    return tileOverlay;
}
 
Example #15
Source File: URLCacheOverlay.java    From mage-android with Apache License 2.0 2 votes vote down vote up
/**
 * Set the tile overlay
 *
 * @param tileOverlay
 */
public synchronized void setTileOverlay(TileOverlay tileOverlay) {
    this.tileOverlay = tileOverlay;
}