
public class HeatMap extends BaseSampleFragment implements org.osmdroid.events.MapListener, Runnable
Demonstrates a way to generate heatmaps using osmdroid and a collection of data points. There's a lot of room for improvement but this class demonstrates two things
There's probably a many options to implement this. This example basically chops up the screen into cells, generates some random data, then iterates all of the data and increments up a counter based on the cell that it was rendered into. Finally the cells are converted into square polygons with a fill color based on the counter.
It's assumed that all required data is available on device for this example.
For future readers: other approaches
TilesOverlay with that source.TilesOverlay with that source.Overlay class that has some custom onDraw logical to paint the image.created on 1/1/2017.
| Modifier and Type | Field and Description |
|---|---|
(package private) String |
alpha |
(package private) int |
cellSizeInDp
the size of the cell in density independent pixels
a higher value = smoother image but higher processing and rendering times
|
(package private) DisplayMetrics |
dm |
(package private) org.osmdroid.views.overlay.FolderOverlay |
heatmapOverlay |
(package private) long |
lastMovement |
(package private) boolean |
needsDataRefresh |
(package private) String |
orange |
(package private) String |
red |
(package private) boolean |
renderJobActive |
(package private) boolean |
running |
(package private) String |
TAG |
(package private) String |
yellow |
mMapView| Constructor and Description |
|---|
HeatMap() |
| Modifier and Type | Method and Description |
|---|---|
void |
addOverlays()
An appropriate place to override and add overlays.
|
String |
getSampleTitle() |
void |
onPause() |
void |
onResume() |
boolean |
onScroll(org.osmdroid.events.ScrollEvent event)
handles the map movement rendering portions, prevents more than one render at a time,
waits for the user to stop moving the map before triggering the render
|
boolean |
onZoom(org.osmdroid.events.ZoomEvent event)
handles the map movement rendering portions, prevents more than one render at a time,
waits for the user to stop moving the map before triggering the render
|
void |
run()
handles the map movement rendering portions, prevents more than one render at a time,
waits for the user to stop moving the map before triggering the render
|
void |
runTestProcedures()
optional place to put automated test procedures, used during the connectCheck tests
this is called OFF of the UI thread.
|
getmMapView, onActivityCreated, onCreate, onCreateOptionsMenu, onCreateView, onDestroy, onDestroyView, onOptionsItemSelected, onPrepareOptionsMenu, skipOnCiTestsString TAG
DisplayMetrics dm
boolean renderJobActive
boolean running
long lastMovement
boolean needsDataRefresh
int cellSizeInDp
String alpha
String red
String orange
String yellow
org.osmdroid.views.overlay.FolderOverlay heatmapOverlay
public String getSampleTitle()
getSampleTitle in class BaseSampleFragmentpublic void addOverlays()
BaseSampleFragmentaddOverlays in class BaseSampleFragmentpublic void onPause()
public void onResume()
public boolean onScroll(org.osmdroid.events.ScrollEvent event)
onScroll in interface org.osmdroid.events.MapListenerpublic boolean onZoom(org.osmdroid.events.ZoomEvent event)
onZoom in interface org.osmdroid.events.MapListenerpublic void run()
public void runTestProcedures()
throws Exception
runTestProcedures in class BaseSampleFragmentException