Anonim / 1 year, 9 months ago | Download | Plaintext | Odpowiedz |

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
package com.rossman;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import android.app.Dialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;
import com.google.android.maps.Projection;

public class ShopMapActivity extends MapActivity {

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_map);
		final CustomMapView mapView = (CustomMapView) findViewById(R.id.mapview);
		mapView.setBuiltInZoomControls(true);
		final List<Overlay> mapOverlays = mapView.getOverlays();
		Drawable drawable = this.getResources().getDrawable(R.drawable.redross);
		final ShopItemizedOverlay itemizedoverlay = new ShopItemizedOverlay(
				drawable, this);
		//listener zoomowania
		mapView.setOnPanAndZoomListener(new OnPanAndZoomListener() {
			public void onZoom() {
				//czyszczenie mapy
				mapOverlays.clear();
				mapView.getOverlays().clear();
				mapView.invalidate();
				mapView.postInvalidate();
				//jezeli zoom jest wiekszy od 9 to rysujemy szczegolowo punkty z danego przedzialu
				if (mapView.getZoomLevel() > 9) {
					Projection proj = mapView.getProjection();
					GeoPoint topLeft = proj.fromPixels(0, 0);
					GeoPoint bottomRight = proj.fromPixels(
							mapView.getWidth() - 1, mapView.getHeight() - 1);
					double topLat = topLeft.getLatitudeE6();
					double topLon = topLeft.getLongitudeE6();
					double bottomLat = bottomRight.getLatitudeE6();
					double bottomLon = bottomRight.getLongitudeE6();

					for (Entry<String, ArrayList<ShopPoint>> entry : Data.shopPointStorage
							.getShopPointMap().entrySet()) {
						for (ShopPoint shopPoint : entry.getValue()) {
							if (((topLon - 50000) < shopPoint.getLon() && shopPoint
									.getLon() < (bottomLon + 50000))
									&& ((topLat + 50000) > shopPoint.getLat() && shopPoint
											.getLat() > (bottomLat - 50000))) {
								GeoPoint point = new GeoPoint((int) shopPoint
										.getLat(), (int) shopPoint.getLon());
								OverlayItem overlayitem = new OverlayItem(
										point, shopPoint.getCity(), shopPoint
												.getStreet());
								itemizedoverlay.addOverlay(overlayitem);
								Log.d("drawnPoints", shopPoint.getCity());
							}
						}
					}
					itemizedoverlay.populateNow();
					mapOverlays.add(itemizedoverlay);
				} else { //jezeli zoom jest mniejszy/rowny 9 rysujemy tylko miasta
					for (String key : Data.shopPointStorage.getShopPointMap()
							.keySet()) {
						ShopPoint shopPoint = Data.shopPointStorage
								.getShopPointMap().get(key).get(0);
						GeoPoint point = new GeoPoint((int) shopPoint.getLat(),
								(int) shopPoint.getLon());
						OverlayItem overlayitem = new OverlayItem(point,
								shopPoint.getCity(), shopPoint.getStreet());
						itemizedoverlay.addOverlay(overlayitem);
						Log.d("drawnPoints", shopPoint.getCity());
					}
					itemizedoverlay.populateNow();
					mapOverlays.add(itemizedoverlay);

				}
			}

			public void onPan() {
			}
		});
		//ustawienia sredoka mapy i zooma
		MapController mp = mapView.getController();
		mp.setCenter(new GeoPoint(52000000, 19000000));
		mp.setZoom(7);
	}

	@Override
	protected boolean isRouteDisplayed() {
		return false;
	}

}