Reputation: 31
I am creating and setting a new tiles starting from a grib data, but the application is very slow:
try {
gribFileTileSource.setRecord(1);
for (int j=0;j<tileSize;j++) {
lat=minLat+j*dLat;
for (int i=0;i<tileSize;i++) {
lon=minLon+i*dLon;
//Log.d(LOG_TAG,"lon:"+lon+" lat:"+lat);
u=gribFileTileSource.getValue(lat,lon);
color=gribFileTileSource.getColor(u);
bitmap.setPixel(i,tileSize-j-1,color);
}
}
How to make this code faster ?
Upvotes: 0
Views: 1261
Reputation: 3258
Sounds like you have a custom tile source and are rendering stuff on the fly. If this is the case, you'll want to take a look at the MapsForge provider that was adapted for osmdroid.
The secret sauce that will help is in the following class: MapsForgeTileModuleProvider
This class performs a similar function, it render's tiles on the fly. After tiles are rendered, they are written to the IFileSystemCache
which can be orders of magnitude faster via SQL than rendering/producing the image every time.
So basically, after you've produced the tile in question, store it in the IFileSystemCache#.saveFile(tileSource, pTile, new ByteArrayInputStream(bitmapdata));
or something to that effect (be sure to close the stream)
After you have the ability to generate your tiles, wire everything together with a class that extends MapTileProviderArray
. Here's the example for the forge stuff:
https://github.com/osmdroid/osmdroid/blob/master/osmdroid-mapsforge/src/main/java/org/osmdroid/mapsforge/MapsForgeTileProvider.java
Note that it creates a MapTileFilesystemProvider, which loads cached tile first, then the tile writer, then the tile provider (which generates tiles on the fly). This Custom Map Tile Provider Array can then be attached to the map using mapView.setTileProvider()
So this won't make tile rendering faster (well, it may since the module supports multiple threads, see this) but the biggest performance impact is storing the rendered tiles in the file system cache.
Upvotes: 1