Search in sources :

Example 1 with KmlFolder

use of org.osmdroid.bonuspack.kml.KmlFolder in project osmbonuspack by MKergall.

the class MapActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Configuration.getInstance().load(this, PreferenceManager.getDefaultSharedPreferences(this));
    MapsForgeTileSource.createInstance(getApplication());
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View v = inflater.inflate(R.layout.main, null);
    setContentView(v);
    SharedPreferences prefs = getSharedPreferences("OSMNAVIGATOR", MODE_PRIVATE);
    MAPBOXSATELLITELABELLED = new MapBoxTileSource("MapBoxSatelliteLabelled", 1, 19, 256, ".png");
    ((MapBoxTileSource) MAPBOXSATELLITELABELLED).retrieveAccessToken(this);
    ((MapBoxTileSource) MAPBOXSATELLITELABELLED).retrieveMapBoxMapId(this);
    TileSourceFactory.addTileSource(MAPBOXSATELLITELABELLED);
    graphHopperApiKey = ManifestUtil.retrieveKey(this, "GRAPHHOPPER_API_KEY");
    flickrApiKey = ManifestUtil.retrieveKey(this, "FLICKR_API_KEY");
    geonamesAccount = ManifestUtil.retrieveKey(this, "GEONAMES_ACCOUNT");
    mapzenApiKey = ManifestUtil.retrieveKey(this, "MAPZEN_APIKEY");
    map = (MapView) v.findViewById(R.id.map);
    String tileProviderName = prefs.getString("TILE_PROVIDER", "Mapnik");
    mNightMode = prefs.getBoolean("NIGHT_MODE", false);
    if ("rendertheme-v4".equals(tileProviderName)) {
        setMapsForgeTileProvider();
    } else {
        try {
            ITileSource tileSource = TileSourceFactory.getTileSource(tileProviderName);
            map.setTileSource(tileSource);
        } catch (IllegalArgumentException e) {
            map.setTileSource(TileSourceFactory.MAPNIK);
        }
    }
    if (mNightMode)
        map.getOverlayManager().getTilesOverlay().setColorFilter(TilesOverlay.INVERT_COLORS);
    map.setTilesScaledToDpi(true);
    map.setMultiTouchControls(true);
    map.setMinZoomLevel(1.0);
    map.setMaxZoomLevel(21.0);
    map.setVerticalMapRepetitionEnabled(false);
    map.setScrollableAreaLimitLatitude(TileSystem.MaxLatitude, -TileSystem.MaxLatitude, 0);
    // Toast.makeText(this, "H="+map.getHeight(), Toast.LENGTH_LONG).show();
    IMapController mapController = map.getController();
    // To use MapEventsReceiver methods, we add a MapEventsOverlay:
    MapEventsOverlay overlay = new MapEventsOverlay(this);
    map.getOverlays().add(overlay);
    mLocationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
    // mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    // mOrientation = mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION);
    // map prefs:
    mapController.setZoom((double) prefs.getFloat("MAP_ZOOM_LEVEL_F", 5));
    mapController.setCenter(new GeoPoint((double) prefs.getFloat("MAP_CENTER_LAT", 48.5f), (double) prefs.getFloat("MAP_CENTER_LON", 2.5f)));
    myLocationOverlay = new DirectedLocationOverlay(this);
    map.getOverlays().add(myLocationOverlay);
    if (savedInstanceState == null) {
        Location location = null;
        if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
            location = mLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
            if (location == null)
                location = mLocationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
        }
        if (location != null) {
            // location known:
            onLocationChanged(location);
        } else {
            // no location known: hide myLocationOverlay
            myLocationOverlay.setEnabled(false);
        }
        startPoint = null;
        destinationPoint = null;
        viaPoints = new ArrayList<GeoPoint>();
    } else {
        myLocationOverlay.setLocation((GeoPoint) savedInstanceState.getParcelable("location"));
        // TODO: restore other aspects of myLocationOverlay...
        startPoint = savedInstanceState.getParcelable("start");
        destinationPoint = savedInstanceState.getParcelable("destination");
        viaPoints = savedInstanceState.getParcelableArrayList("viapoints");
    }
    ScaleBarOverlay scaleBarOverlay = new ScaleBarOverlay(map);
    map.getOverlays().add(scaleBarOverlay);
    // Itinerary markers:
    mItineraryMarkers = new FolderOverlay();
    mItineraryMarkers.setName(getString(R.string.itinerary_markers_title));
    map.getOverlays().add(mItineraryMarkers);
    mViaPointInfoWindow = new ViaPointInfoWindow(R.layout.itinerary_bubble, map);
    updateUIWithItineraryMarkers();
    // Tracking system:
    mTrackingModeButton = (Button) findViewById(R.id.buttonTrackingMode);
    mTrackingModeButton.setOnClickListener(new View.OnClickListener() {

        public void onClick(View view) {
            mTrackingMode = !mTrackingMode;
            updateUIWithTrackingMode();
        }
    });
    if (savedInstanceState != null) {
        mTrackingMode = savedInstanceState.getBoolean("tracking_mode");
        updateUIWithTrackingMode();
    } else
        mTrackingMode = false;
    // TODO restore state
    mIsRecordingTrack = false;
    AutoCompleteOnPreferences departureText = (AutoCompleteOnPreferences) findViewById(R.id.editDeparture);
    departureText.setPrefKeys(SHARED_PREFS_APPKEY, PREF_LOCATIONS_KEY);
    Button searchDepButton = (Button) findViewById(R.id.buttonSearchDep);
    searchDepButton.setOnClickListener(new View.OnClickListener() {

        public void onClick(View view) {
            handleSearchButton(START_INDEX, R.id.editDeparture);
        }
    });
    AutoCompleteOnPreferences destinationText = (AutoCompleteOnPreferences) findViewById(R.id.editDestination);
    destinationText.setPrefKeys(SHARED_PREFS_APPKEY, PREF_LOCATIONS_KEY);
    Button searchDestButton = (Button) findViewById(R.id.buttonSearchDest);
    searchDestButton.setOnClickListener(new View.OnClickListener() {

        public void onClick(View view) {
            handleSearchButton(DEST_INDEX, R.id.editDestination);
        }
    });
    View expander = findViewById(R.id.expander);
    expander.setOnClickListener(new View.OnClickListener() {

        public void onClick(View view) {
            View searchPanel = findViewById(R.id.search_panel);
            if (searchPanel.getVisibility() == View.VISIBLE) {
                searchPanel.setVisibility(View.GONE);
            } else {
                searchPanel.setVisibility(View.VISIBLE);
            }
        }
    });
    View searchPanel = findViewById(R.id.search_panel);
    searchPanel.setVisibility(prefs.getInt("PANEL_VISIBILITY", View.VISIBLE));
    registerForContextMenu(searchDestButton);
    // context menu for clicking on the map is registered on this button.
    // (a little bit strange, but if we register it on mapView, it will catch map drag events)
    // Route and Directions
    mWhichRouteProvider = prefs.getInt("ROUTE_PROVIDER", OSRM);
    mRoadNodeMarkers = new FolderOverlay();
    mRoadNodeMarkers.setName("Route Steps");
    map.getOverlays().add(mRoadNodeMarkers);
    if (savedInstanceState != null) {
        // STATIC mRoad = savedInstanceState.getParcelable("road");
        updateUIWithRoads(mRoads);
    }
    // POIs:
    // POI search interface:
    String[] poiTags = getResources().getStringArray(R.array.poi_tags);
    poiTagText = (AutoCompleteTextView) findViewById(R.id.poiTag);
    ArrayAdapter<String> poiAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, poiTags);
    poiTagText.setAdapter(poiAdapter);
    Button setPOITagButton = (Button) findViewById(R.id.buttonSetPOITag);
    setPOITagButton.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            // Hide the soft keyboard:
            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(poiTagText.getWindowToken(), 0);
            // Start search:
            String feature = poiTagText.getText().toString();
            if (!feature.equals(""))
                Toast.makeText(v.getContext(), "Searching:\n" + feature, Toast.LENGTH_LONG).show();
            getPOIAsync(feature);
        }
    });
    // POI markers:
    mPoiMarkers = new RadiusMarkerClusterer(this);
    Bitmap clusterIcon = BonusPackHelper.getBitmapFromVectorDrawable(this, R.drawable.marker_poi_cluster);
    mPoiMarkers.setIcon(clusterIcon);
    mPoiMarkers.mAnchorV = Marker.ANCHOR_BOTTOM;
    mPoiMarkers.mTextAnchorU = 0.70f;
    mPoiMarkers.mTextAnchorV = 0.27f;
    mPoiMarkers.getTextPaint().setTextSize(12 * getResources().getDisplayMetrics().density);
    map.getOverlays().add(mPoiMarkers);
    if (savedInstanceState != null) {
        // STATIC - mPOIs = savedInstanceState.getParcelableArrayList("poi");
        updateUIWithPOI(mPOIs, "");
    }
    // KML handling:
    mKmlOverlay = null;
    if (savedInstanceState != null) {
        // STATIC - mKmlDocument = savedInstanceState.getParcelable("kml");
        updateUIWithKml();
    } else {
        // first launch:
        mKmlDocument = new KmlDocument();
        mKmlStack = new Stack<KmlFeature>();
        mKmlClipboard = new KmlFolder();
        // check if intent has been passed with a kml URI to load (url or file)
        Intent onCreateIntent = getIntent();
        if (onCreateIntent.getAction().equals(Intent.ACTION_VIEW)) {
            String uri = onCreateIntent.getDataString();
            openFile(uri, true, false);
        }
    }
    // Sharing
    mFriendsManager = new FriendsManager(this, map);
    mFriendsManager.onCreate(savedInstanceState);
    checkPermissions();
    Button menuButton = (Button) findViewById(R.id.buttonMenu);
    menuButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            openOptionsMenu();
        }
    });
}
Also used : MapEventsOverlay(org.osmdroid.views.overlay.MapEventsOverlay) InputMethodManager(android.view.inputmethod.InputMethodManager) DirectedLocationOverlay(org.osmdroid.views.overlay.mylocation.DirectedLocationOverlay) ScaleBarOverlay(org.osmdroid.views.overlay.ScaleBarOverlay) GeoPoint(org.osmdroid.util.GeoPoint) Bitmap(android.graphics.Bitmap) Button(android.widget.Button) IMapController(org.osmdroid.api.IMapController) FolderOverlay(org.osmdroid.views.overlay.FolderOverlay) SharedPreferences(android.content.SharedPreferences) RadiusMarkerClusterer(org.osmdroid.bonuspack.clustering.RadiusMarkerClusterer) Intent(android.content.Intent) AutoCompleteTextView(android.widget.AutoCompleteTextView) MapView(org.osmdroid.views.MapView) View(android.view.View) TextView(android.widget.TextView) KmlFeature(org.osmdroid.bonuspack.kml.KmlFeature) LayoutInflater(android.view.LayoutInflater) KmlFolder(org.osmdroid.bonuspack.kml.KmlFolder) MapBoxTileSource(org.osmdroid.tileprovider.tilesource.MapBoxTileSource) ITileSource(org.osmdroid.tileprovider.tilesource.ITileSource) ArrayAdapter(android.widget.ArrayAdapter) KmlDocument(org.osmdroid.bonuspack.kml.KmlDocument) Location(android.location.Location)

Example 2 with KmlFolder

use of org.osmdroid.bonuspack.kml.KmlFolder in project osmbonuspack by MKergall.

the class MapActivity method insertOverlaysInKml.

void insertOverlaysInKml() {
    KmlFolder root = mKmlDocument.mKmlRoot;
    // Insert relevant overlays inside:
    if (mItineraryMarkers.getItems().size() > 0)
        root.addOverlay(mItineraryMarkers, mKmlDocument);
    if (mRoadOverlays != null) {
        for (int i = 0; i < mRoadOverlays.length; i++) root.addOverlay(mRoadOverlays[i], mKmlDocument);
    }
    if (mRoadNodeMarkers.getItems().size() > 0)
        root.addOverlay(mRoadNodeMarkers, mKmlDocument);
    root.addOverlay(mDestinationPolygon, mKmlDocument);
    if (mPoiMarkers.getItems().size() > 0) {
        root.addOverlay(mPoiMarkers, mKmlDocument);
    }
}
Also used : KmlFolder(org.osmdroid.bonuspack.kml.KmlFolder) KmlPoint(org.osmdroid.bonuspack.kml.KmlPoint) Paint(android.graphics.Paint) GeoPoint(org.osmdroid.util.GeoPoint)

Example 3 with KmlFolder

use of org.osmdroid.bonuspack.kml.KmlFolder in project osmbonuspack by MKergall.

the class KmlTreeActivity method onContextItemSelected.

@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
    KmlFolder currentKmlFolder = (KmlFolder) mCurrentKmlFeature;
    switch(item.getItemId()) {
        case // =move to the emptied clipboard
        R.id.kml_item_menu_cut:
            mKmlClipboard.mItems.clear();
            mKmlClipboard.add(currentKmlFolder.mItems.get(info.position));
            currentKmlFolder.removeItem(info.position);
            mListAdapter.notifyDataSetChanged();
            return true;
        case R.id.kml_item_menu_copy:
            KmlFeature copy = currentKmlFolder.mItems.get(info.position).clone();
            mKmlClipboard.mItems.clear();
            mKmlClipboard.mItems.add(copy);
            return true;
        case R.id.kml_item_menu_behind:
            if (info.position > 0) {
                KmlFeature kmlItem = currentKmlFolder.removeItem(info.position);
                currentKmlFolder.mItems.add(info.position - 1, kmlItem);
                mListAdapter.notifyDataSetChanged();
            }
            return true;
        case R.id.kml_item_menu_front:
            if (info.position < currentKmlFolder.mItems.size() - 1) {
                KmlFeature kmlItem = currentKmlFolder.removeItem(info.position);
                currentKmlFolder.mItems.add(info.position + 1, kmlItem);
                mListAdapter.notifyDataSetChanged();
            }
            return true;
        case R.id.kml_item_menu_show_on_map:
            Intent intent = new Intent();
            // TODO: is it the right way to pass a handle to an object?
            intent.putExtra("KML_FEATURE", currentKmlFolder.mItems.get(info.position));
            saveCurrentFeature();
            setResult(RESULT_OK, intent);
            finish();
            return true;
        default:
            return super.onContextItemSelected(item);
    }
}
Also used : AdapterContextMenuInfo(android.widget.AdapterView.AdapterContextMenuInfo) KmlFolder(org.osmdroid.bonuspack.kml.KmlFolder) Intent(android.content.Intent) KmlFeature(org.osmdroid.bonuspack.kml.KmlFeature)

Example 4 with KmlFolder

use of org.osmdroid.bonuspack.kml.KmlFolder in project osmbonuspack by MKergall.

the class KmlListAdapter method getView.

@Override
public View getView(int position, View convertView, ViewGroup viewGroup) {
    KmlFeature item = (KmlFeature) getItem(position);
    if (convertView == null) {
        LayoutInflater inflater = (LayoutInflater) viewGroup.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = inflater.inflate(R.layout.kml_list_item, null);
    }
    TextView itemText = (TextView) convertView.findViewById(R.id.listItemTxt);
    itemText.setText(item.mName);
    // Handle checkbox:
    /*
        CheckBox checkBoxIsVisible = (CheckBox)convertView.findViewById(R.id.listItemCheckbox);
        checkBoxIsVisible.setChecked(mRoot.mItems.get(position).mVisibility);
        if (checkBoxIsVisible != null) {
	        checkBoxIsVisible.setOnClickListener(new OnClickListener(){
				@Override public void onClick(View view) {
					int position = (Integer)view.getTag();
					KmlFeature item = mRoot.mItems.get(position);
					item.mVisibility = ((CheckBox)view).isChecked();
				}
	        });
	        checkBoxIsVisible.setTag(position);
        }
        */
    ImageView img = (ImageView) convertView.findViewById(R.id.listItemImg);
    if (item instanceof KmlFolder) {
        img.setImageResource(R.drawable.moreinfo_arrow);
    } else if (item instanceof KmlPlacemark) {
        KmlGeometry geometry = ((KmlPlacemark) item).mGeometry;
        if (geometry instanceof KmlPoint)
            img.setImageResource(R.drawable.marker_kml_point);
        else if (geometry instanceof KmlLineString)
            img.setImageResource(R.drawable.kml_icon_linestring);
        else if (geometry instanceof KmlPolygon)
            img.setImageResource(R.drawable.kml_icon_polygon);
        else if (geometry instanceof KmlMultiGeometry)
            img.setImageResource(R.drawable.kml_icon_multigeometry);
        else if (geometry instanceof KmlTrack)
            img.setImageResource(R.drawable.kml_icon_gxtrack);
        else
            img.setImageDrawable(null);
    } else if (item instanceof KmlGroundOverlay) {
        img.setImageResource(R.drawable.kml_icon_groundoverlay);
    } else
        img.setImageDrawable(null);
    return convertView;
}
Also used : KmlPoint(org.osmdroid.bonuspack.kml.KmlPoint) KmlMultiGeometry(org.osmdroid.bonuspack.kml.KmlMultiGeometry) KmlFeature(org.osmdroid.bonuspack.kml.KmlFeature) KmlGroundOverlay(org.osmdroid.bonuspack.kml.KmlGroundOverlay) LayoutInflater(android.view.LayoutInflater) KmlFolder(org.osmdroid.bonuspack.kml.KmlFolder) TextView(android.widget.TextView) KmlGeometry(org.osmdroid.bonuspack.kml.KmlGeometry) ImageView(android.widget.ImageView) KmlPlacemark(org.osmdroid.bonuspack.kml.KmlPlacemark) KmlPolygon(org.osmdroid.bonuspack.kml.KmlPolygon) KmlLineString(org.osmdroid.bonuspack.kml.KmlLineString) KmlTrack(org.osmdroid.bonuspack.kml.KmlTrack)

Example 5 with KmlFolder

use of org.osmdroid.bonuspack.kml.KmlFolder in project osmbonuspack by MKergall.

the class KmlTreeActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.kml_main);
    mListView = (ListView) findViewById(R.id.listviewKml);
    registerForContextMenu(mListView);
    mCurrentKmlFeature = MapActivity.mKmlStack.peek();
    mKmlClipboard = MapActivity.mKmlClipboard;
    eHeader = (EditText) findViewById(R.id.name);
    eHeader.setText(mCurrentKmlFeature.mName);
    eDescription = (EditText) findViewById(R.id.description);
    eDescription.setText(mCurrentKmlFeature.mDescription);
    sStyleSpinner = (Spinner) findViewById(R.id.styleSpinner);
    ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, stylesWithEmpty());
    spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    sStyleSpinner.setAdapter(spinnerAdapter);
    if (mCurrentKmlFeature.mStyle != null) {
        int spinnerPosition = spinnerAdapter.getPosition(mCurrentKmlFeature.mStyle);
        sStyleSpinner.setSelection(spinnerPosition);
    }
    CheckBox cVisible = (CheckBox) findViewById(R.id.checkbox_visible);
    cVisible.setChecked(mCurrentKmlFeature.mVisibility);
    if (mCurrentKmlFeature instanceof KmlFolder) {
        mListAdapter = new KmlListAdapter(this, (KmlFolder) mCurrentKmlFeature);
        // setting list adapter
        mListView.setAdapter(mListAdapter);
        // Listview on child click listener
        mListView.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> arg0, View view, int position, long index) {
                mItemPosition = position;
                KmlFeature item = ((KmlFolder) mCurrentKmlFeature).mItems.get(position);
                Intent myIntent = new Intent(view.getContext(), KmlTreeActivity.class);
                // myIntent.putExtra("KML", item);
                MapActivity.mKmlStack.push(item);
                startActivityForResult(myIntent, KML_TREE_REQUEST);
            }
        });
    }
}
Also used : OnItemClickListener(android.widget.AdapterView.OnItemClickListener) Intent(android.content.Intent) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) KmlFeature(org.osmdroid.bonuspack.kml.KmlFeature) CheckBox(android.widget.CheckBox) KmlFolder(org.osmdroid.bonuspack.kml.KmlFolder) ArrayAdapter(android.widget.ArrayAdapter)

Aggregations

KmlFolder (org.osmdroid.bonuspack.kml.KmlFolder)7 KmlFeature (org.osmdroid.bonuspack.kml.KmlFeature)6 Intent (android.content.Intent)3 KmlPoint (org.osmdroid.bonuspack.kml.KmlPoint)3 GeoPoint (org.osmdroid.util.GeoPoint)3 Bitmap (android.graphics.Bitmap)2 Paint (android.graphics.Paint)2 LayoutInflater (android.view.LayoutInflater)2 View (android.view.View)2 ArrayAdapter (android.widget.ArrayAdapter)2 TextView (android.widget.TextView)2 IMapController (org.osmdroid.api.IMapController)2 RadiusMarkerClusterer (org.osmdroid.bonuspack.clustering.RadiusMarkerClusterer)2 KmlDocument (org.osmdroid.bonuspack.kml.KmlDocument)2 KmlLineString (org.osmdroid.bonuspack.kml.KmlLineString)2 FolderOverlay (org.osmdroid.views.overlay.FolderOverlay)2 SharedPreferences (android.content.SharedPreferences)1 BitmapDrawable (android.graphics.drawable.BitmapDrawable)1 Drawable (android.graphics.drawable.Drawable)1 Location (android.location.Location)1