use of org.mapsforge.map.android.view.MapView in project satstat by mvglasow.
the class MapSectionFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
mainActivity = (MainActivity) this.getContext();
View rootView = inflater.inflate(R.layout.fragment_main_map, container, false);
float density = this.getContext().getResources().getDisplayMetrics().density;
String versionName;
try {
versionName = mainActivity.getPackageManager().getPackageInfo(mainActivity.getPackageName(), 0).versionName;
} catch (NameNotFoundException e) {
versionName = "unknown";
}
mapReattach = (ImageButton) rootView.findViewById(R.id.mapReattach);
mapAttribution = (TextView) rootView.findViewById(R.id.mapAttribution);
mapReattach.setVisibility(View.GONE);
isMapViewAttached = true;
OnClickListener clis = new OnClickListener() {
@Override
public void onClick(View v) {
if (v == mapReattach) {
isMapViewAttached = true;
mapReattach.setVisibility(View.GONE);
updateMap();
}
}
};
mapReattach.setOnClickListener(clis);
// Initialize controls
mapMap = new MapView(rootView.getContext());
((FrameLayout) rootView).addView(mapMap, 0);
mapMap.setClickable(true);
mapMap.getMapScaleBar().setVisible(true);
mapMap.getMapScaleBar().setMarginVertical((int) (density * 16));
mapMap.setBuiltInZoomControls(true);
mapMap.getMapZoomControls().setZoomLevelMin((byte) 10);
mapMap.getMapZoomControls().setZoomLevelMax((byte) 20);
mapMap.getMapZoomControls().setZoomControlsOrientation(Orientation.VERTICAL_IN_OUT);
mapMap.getMapZoomControls().setZoomInResource(R.drawable.zoom_control_in);
mapMap.getMapZoomControls().setZoomOutResource(R.drawable.zoom_control_out);
mapMap.getMapZoomControls().setMarginHorizontal((int) (density * 8));
mapMap.getMapZoomControls().setMarginVertical((int) (density * 16));
providerLocations = new HashMap<String, Location>();
mAvailableProviderStyles = new ArrayList<String>(Arrays.asList(Const.LOCATION_PROVIDER_STYLES));
providerStyles = new HashMap<String, String>();
providerAppliedStyles = new HashMap<String, String>();
providerInvalidationHandler = new Handler();
providerInvalidators = new HashMap<String, Runnable>();
onlineTileSource = new OnlineTileSource(Const.TILE_SERVER_OSM, 80);
onlineTileSource.setUserAgent(String.format("%s/%s (%s)", "SatStat", versionName, System.getProperty("http.agent")));
onlineTileSource.setName(Const.TILE_CACHE_OSM).setAlpha(false).setBaseUrl(Const.TILE_URL_OSM).setExtension(Const.TILE_EXTENSION_OSM).setParallelRequestsLimit(8).setProtocol("http").setTileSize(256).setZoomLevelMax((byte) 18).setZoomLevelMin((byte) 0);
GestureDetector gd = new GestureDetector(rootView.getContext(), new GestureDetector.SimpleOnGestureListener() {
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
mapReattach.setVisibility(View.VISIBLE);
isMapViewAttached = false;
return false;
}
});
mapMap.setGestureDetector(gd);
mainActivity.mapSectionFragment = this;
float lat = mainActivity.mSharedPreferences.getFloat(Const.KEY_PREF_MAP_LAT, 360.0f);
float lon = mainActivity.mSharedPreferences.getFloat(Const.KEY_PREF_MAP_LON, 360.0f);
if ((lat < 360.0f) && (lon < 360.0f)) {
mapMap.getModel().mapViewPosition.setCenter(new LatLong(lat, lon));
}
int zoom = mainActivity.mSharedPreferences.getInt(Const.KEY_PREF_MAP_ZOOM, 16);
mapMap.getModel().mapViewPosition.setZoomLevel((byte) zoom);
createLayers(true);
return rootView;
}
Aggregations