GISDemo

111111111111111111

public class Demo extends Activity {
	public static final String INTENT_QUERY = "cn.hotgis.QueryUI";
	public static final String INTENT_RESULT = "cn.hotgis.RESULTUI";
	public static final String INTENT_STEP3 = "com.novoda.STEP3";

	private static final int QUERY = 1;
	private static final int RESULT = 2;

	boolean bDraw = false;
	double loc_x = 0, loc_y = 0;
	// 文件夹名称
	String foldername = "test3";
	// 地图资源路径
	String path = "/" + foldername + "/" + foldername + ".map";
	double x;
	double y;

	List<PointInfoModel> pointList;
	PointInfoModel pointInfo;
	AlertDialog selectDialog;
	private List<Map<String, Object>> mData;

	eMyMapWnd2 m_myMapWnd = null;
	eMyMapWnd2 m_myMapWnd2 = null;
	boolean m_bRotate = false;
	@SuppressWarnings("unused")
	private SensorManager sensorMgr;
	int penI = 0;
	@SuppressWarnings("unused")
	private final static int CWJ_HEAP_SIZE = 6 * 1024 * 1024;

	public class eMyMapWnd2 extends eMyMapWnd {
		public eMyMapWnd2(Context context) {
			super(context);
		}

		@Override
		public void OnGeometrySelected(int count) {
			pointList = new ArrayList<PointInfoModel>();
			int c = m_myMapWnd.GetMap().Selection().GetCount();
			System.out.println("c=" + c);
			for (int i = 0; i < c; i++) {
				eMyResultSet rs = m_myMapWnd.GetMap().Selection().GetAt(i);
				System.out.println("所属层名:" + rs.GetLayer().GetName());
				rs.Reset();
				while (rs.HasNext()) {
					eMyPoint point = rs.GetGeometry().GetPointAt(0);// 获取逻辑坐标
					eMyPoint2D point2D = m_myMapWnd.GetMap().MapToGeo(point);// 转物理坐标
					x = point2D.GetX();
					y = point2D.GetY();
					pointInfo = new PointInfoModel();
					pointInfo.setX(x);
					pointInfo.setY(y);
					pointInfo.setName(rs.GetString(0).toString());
					pointInfo.setId(rs.GetString(1).toString());
					pointInfo.setCity(rs.GetString(2).toString());
					pointInfo.setArea(rs.GetString(3).toString());
					pointInfo.setCategory(rs.GetString(4).toString());
					pointInfo.setGeocode(rs.GetString(5).toString());

					pointList.add(pointInfo);

				}
			}

			// 输出显示结果
			if (pointList.size() > 0) {
				// 点选
				// if (pointList.size() == 1) {
				// double x = pointList.get(0).getX();
				// double y = pointList.get(0).getY();
				// String name = pointList.get(0).getName();
				// String id = pointList.get(0).getId();
				// String city = pointList.get(0).getCity();
				// String area = pointList.get(0).getArea();
				// String category = pointList.get(0).getCategory();
				// String geocode = pointList.get(0).getGeocode();
				// show(0, name, id, city, area, category, geocode, x, y);
				//
				// }
				// 多选
				// else {
				// for (int i = 0; i < pointList.size(); i++) {
				// double x = pointList.get(i).getX();
				// double y = pointList.get(i).getY();
				// String name = pointList.get(i).getName();
				// String id = pointList.get(i).getId();
				// String city = pointList.get(i).getCity();
				// String area = pointList.get(i).getArea();
				// String category = pointList.get(i).getCategory();
				// String geocode = pointList.get(i).getGeocode();
				// show(i, name, id, city, area, category, geocode, x,
				// y);
				// }

				mData = new ArrayList<Map<String, Object>>();
				Map<String, Object> map = new HashMap<String, Object>();
				for (int i = 0; i < pointList.size(); i++) {
					map = new HashMap<String, Object>();
					map.put("name", pointList.get(i).getName());
					map.put("pointx", pointList.get(i).getX());
					map.put("pointy", pointList.get(i).getY());
					map.put("area", pointList.get(i).getArea());
					map.put("geocode", pointList.get(i).getGeocode());
					mData.add(map);
				}
				MyAdapter myAdapter = new MyAdapter(Demo.this, mData);
				showDialog(myAdapter);// 显示选中列表
			}
			// }
			// Toast.makeText(Demo.this, text, 9000).show();
		}

		protected Drawable boundCenterBottom(Drawable balloon) {
			int markerWidth = balloon.getIntrinsicWidth();
			int markerHeight = balloon.getIntrinsicHeight();

			Rect srcRect = balloon.getBounds();
			srcRect.offset(-markerWidth / 2, -markerHeight);
			balloon.setBounds(srcRect);
			return balloon;
		}

		@Override
		public void OnDraw(Canvas canvas) {
			// if (bDraw = true)
			// return;
			Paint paint = new Paint();
			// loc_x = 120.46158699979;
			// loc_y = 36.09769800014725;
			eMyPoint pt = m_myMapWnd.GeoToPixel(new eMyPoint2D(loc_x, loc_y));
			Point myScreenCoords = new Point((int) pt.GetX(), (int) pt.GetY());
			// 转换当前地图位置到屏幕坐标点
			// mv.getProjection().toPixels(gp1, myScreenCoords);
			paint.setStrokeWidth(1);
			paint.setARGB(255, 255, 0, 0);
			paint.setStyle(Paint.Style.FILL);
			@SuppressWarnings("unused")
			Bitmap bm = BitmapFactory.decodeResource(getResources(),
					R.drawable.location);
			canvas.save(Canvas.MATRIX_SAVE_FLAG);
			// 加载两次图片资源
			Drawable drawable = getResources().getDrawable(R.drawable.location);
			// 这里调用mutate 做测试
			Drawable drawable1 = getResources()
					.getDrawable(R.drawable.location).mutate();
			drawable.setBounds(myScreenCoords.x, myScreenCoords.y,
					myScreenCoords.x + drawable.getIntrinsicWidth(),
					myScreenCoords.y + drawable.getIntrinsicHeight());
			drawable1.setBounds(0, 0, drawable1.getIntrinsicWidth(), drawable1
					.getIntrinsicHeight());
			// 位置的调节操作
			boundCenterBottom(drawable);
			drawable.draw(canvas);
			canvas.restore();
			canvas.save(Canvas.MATRIX_SAVE_FLAG);
			// 颜色的过滤
			drawable1.setColorFilter(0x7f000000, PorterDuff.Mode.SRC_IN);
			// 位移操作
			canvas.translate(myScreenCoords.x, myScreenCoords.y);
			// 倾斜操作
			canvas.skew(-0.9F, 0.0F);
			// 进行缩放
			canvas.scale(1.0F, 0.5F);
			boundCenterBottom(drawable1);
			drawable1.draw(canvas);
			// 这里清除颜色过滤
			drawable1.clearColorFilter();
			canvas.restore();
		}
	}

	// 弹出对话框
	public void showDialog(MyAdapter myAdapter) {
		LayoutInflater inflater = LayoutInflater.from(Demo.this);// 渲染器
		View customdialog2view = inflater.inflate(R.layout.dialog_select, null);

		// 自定义的透明dialog-----------------------------------------------------
		// 创建Dialog并设置样式主题
		SelectDialog selectDialog = new SelectDialog(Demo.this, R.style.dialog);

		// 设置点击Dialog外部任意区域关闭Dialog
		selectDialog.setCanceledOnTouchOutside(true);

		selectDialog.setContentView(customdialog2view);
		// selectDialog.setTitle("选中列表:");

		// 系统dialog-----------------------------------------------------
		// AlertDialog.Builder builder = new AlertDialog.Builder(Demo.this);
		// builder.setTitle("选中列表:");
		// builder.setView(customdialog2view);
		// builder.setNegativeButton("取消",
		// new DialogInterface.OnClickListener() {
		// public void onClick(DialogInterface dialog, int which) {
		// }
		// });

		ListView listView = (ListView) customdialog2view
				.findViewById(R.id.listview);
		listView.setAdapter(myAdapter);
		listView.setItemsCanFocus(false);
		listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
		listView.setOnItemClickListener(new OnItemClickListener() {
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				ViewHolder viewHolder = (ViewHolder) view.getTag();
				String name = viewHolder.name.getText().toString();
				String area = viewHolder.area.getText().toString();
				String geocode = viewHolder.geocode.getText().toString();
				String x = viewHolder.point_x.getText().toString();
				String y = viewHolder.point_y.getText().toString();
				show(0, name, "", "", area, "", geocode, Double.valueOf(x),
						Double.valueOf(y));
			}
		});

		// 如果使用系统Dialog,请去掉该句注释
		// selectDialog = builder.create();
		selectDialog.show();
	}

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		m_myMapWnd = new eMyMapWnd2(this);
		setContentView(m_myMapWnd);

		// 初始化Location
		initLocation();

		// =========================================================
		WindowManager wm = (WindowManager) this
				.getSystemService(Context.WINDOW_SERVICE);
		int screenWidth = wm.getDefaultDisplay().getWidth();// 屏幕宽度
		int screenHeight = wm.getDefaultDisplay().getHeight();// 屏幕高度
		Rect rect = new Rect();
		this.getWindow().getDecorView().getWindowVisibleDisplayFrame(rect);
		// 旋转
		// m_myView.m_myMapWnd.m_map.DrawParam().SetRotateAngle(45);
		m_myMapWnd.setSize(screenWidth, screenHeight - 50);
		// 打开文件
		File sdDir = null;
		boolean sdCardExist = Environment.getExternalStorageState().equals(
				android.os.Environment.MEDIA_MOUNTED); // 判断sd卡是否存在
		if (sdCardExist) {
			sdDir = Environment.getExternalStorageDirectory();// 获取跟目录
			String sdPath = sdDir.toString();
			String fileName = sdPath + path;// 以name存在目录中
			double firClick = System.currentTimeMillis();
			boolean bRet = m_myMapWnd.Open(fileName);
			double secClick = System.currentTimeMillis();
			double distanceTime = secClick - firClick;
			String cost = String.valueOf(distanceTime);
			if (bRet) {
				int c = m_myMapWnd.GetMap().GetLayerCount();
				for (int i = 0; i < c; i++) {
					eMyLayer pLayer = m_myMapWnd.GetMap().GetLayerAt(i);
				}
			}
		}
		m_myMapWnd.GetMap().Compass().visible = true;
		m_myMapWnd.GetMap().Scale().visible = true;
	}

	private LocationManager locationManager;
	private Location location;
	private Criteria criteria;
	private String provider;

	@SuppressWarnings("static-access")
	private void initLocation() {
		// 初始化locationManager:获得系统所提供的location_service
		locationManager = (LocationManager) getSystemService(this.LOCATION_SERVICE);
		// 精度比较高,但是慢而且消耗电力, 而且可能因为天气原因或者障碍物而无法获取卫星信息,另外设备可能没有GPS模块
		// if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)){
		// 通过网络获取定位信息,精度低,耗电少,获取信息速度较快,不依赖GPS模块
		if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
			criteria = new Criteria();
			criteria.setAccuracy(Criteria.ACCURACY_FINE);// 高精度
			criteria.setAltitudeRequired(false);// 海拔
			criteria.setBearingRequired(false);// 方向
			criteria.setSpeedRequired(false);// 速度
			criteria.setCostAllowed(false);// 不允许有花费
			criteria.setPowerRequirement(Criteria.POWER_LOW);// 低功耗
			provider = locationManager.getBestProvider(criteria, true);
			// 位置变化监听,默认5秒一次,距离10米以上
			locationManager.requestLocationUpdates(provider, 5000, 10,
					locationListener);
		} else {
			showGPSDate(null, -1);
		}
	}

	@SuppressWarnings("unused")
	private final SensorEventListener mSensorEventListener = new SensorEventListener() {
		public void onSensorChanged(SensorEvent event) {
			if (event.sensor.getType() == Sensor.TYPE_ORIENTATION) {
				float x;
				x = event.values[SensorManager.DATA_X];
				if (m_myMapWnd != null && m_bRotate) {
					m_myMapWnd.SetRotateAngle(x);
					m_myMapWnd.reDraw();
					m_myMapWnd.repaint(0, 0);
				}
			}
		}

		public void onAccuracyChanged(Sensor sensor, int accuracy) {
		}
	};

	@Override
	public void onWindowFocusChanged(boolean hasFocus) {
		// TODO Auto-generated method stub
		super.onWindowFocusChanged(hasFocus);
		Rect frame = new Rect();
		getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
		int statusBarHeight = frame.top;

		int contentTop = getWindow().findViewById(Window.ID_ANDROID_CONTENT)
				.getTop();
		// statusBarHeight是上面所求的状态栏的高度
		@SuppressWarnings("unused")
		int titleBarHeight = contentTop - statusBarHeight;

		// textView = (TextView)findViewById(R.id.textView1);
		// textView.setText("状态栏的高度" + Integer.toString(titleBarHeight));
	}

	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		switch (requestCode) {
		case QUERY:

			bDraw = false;
			String Keyword = data.getStringExtra("Keyword");
			int index = data.getIntExtra("Index", 0);
			eMyLayer lyr = m_myMapWnd.GetMap().GetLayerAt(index);
			eMyQueryDefn qd = new eMyQueryDefn();
			String wc = " OBJNAME like '%";
			wc += Keyword;
			wc += "%'";
			qd.SetWhereClause(wc);
			eMyResultSet rs = lyr.Query(qd);
			String str = "";
			String[] value = new String[rs.GetCount()];
			String[] coor = new String[rs.GetCount()];

			int j = 0;
			while (rs.HasNext()) {
				str += rs.GetString(0);
				str += rs.GetString(1);
				str += rs.GetString(2);
				str += rs.GetString(3);
				str += rs.GetString(4);
				str += rs.GetString(5);
				value[j] = str;
				str = "";
				int x = rs.GetGeometry().GetPointAt(0).GetX();
				int y = rs.GetGeometry().GetPointAt(0).GetY();
				eMyPoint2D pt = m_myMapWnd.GetMap()
						.MapToGeo(new eMyPoint(x, y));
				coor[j] = String.valueOf(pt.GetX()) + ","
						+ String.valueOf(pt.GetY());
				j++;
			}
			Intent intent = new Intent();
			intent.setClass(Demo.this, ResultUI.class);
			Bundle bundle = new Bundle();
			bundle.putSerializable("rs_string", value);
			bundle.putSerializable("rs_coor", coor);
			intent.putExtras(bundle);
			startActivityForResult(intent, RESULT);

			break;
		case RESULT:
			// 定位
		{
			@SuppressWarnings("unused")
			String R_Keyword = data.getStringExtra("R_Keyword");
			String R_Coor = data.getStringExtra("R_Coor");
			String[] xy = R_Coor.split(",");
			bDraw = true;
			loc_x = Double.valueOf(xy[0]);
			loc_y = Double.valueOf(xy[1]);
			m_myMapWnd.ZoomTo(loc_x, loc_y, 0.002);
			m_myMapWnd.reDraw();
			m_myMapWnd.repaint(0, 0);
			break;
		}
		}
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		switch (keyCode) {
		case KeyEvent.KEYCODE_DPAD_LEFT:
			m_myMapWnd.pan(20, 0);
			break;
		case KeyEvent.KEYCODE_DPAD_RIGHT:
			m_myMapWnd.pan(-20, 0);
			break;
		case KeyEvent.KEYCODE_DPAD_UP:
			m_myMapWnd.pan(0, -20);
			break;
		case KeyEvent.KEYCODE_DPAD_DOWN:
			m_myMapWnd.pan(0, 20);
			break;
		case KeyEvent.KEYCODE_DPAD_CENTER:
			m_myMapWnd.ZoomByRatio(1 / 1.1);
			break;
		case KeyEvent.KEYCODE_BACK:
			if (event.getRepeatCount() == 0) {
				AlertDialog.Builder builder = new AlertDialog.Builder(this);
				builder.setMessage("确定退出本程序吗?").setTitle("提示").setCancelable(
						false).setPositiveButton("确定",
						new DialogInterface.OnClickListener() {
							public void onClick(DialogInterface dialog, int id) {
								finish();
								System.exit(0);
							}
						}).setNegativeButton("取消",
						new DialogInterface.OnClickListener() {
							public void onClick(DialogInterface dialog, int id) {
								dialog.cancel();
							}
						}).show();
				return false;

			}
			break;
		}
		double firClick = System.currentTimeMillis();

		m_myMapWnd.reDraw();
		m_myMapWnd.repaint(0, 0);
		double secClick = System.currentTimeMillis();
		double distanceTime = secClick - firClick;
		@SuppressWarnings("unused")
		String cost = String.valueOf(distanceTime);
		// Toast.makeText(this, cost, Toast.LENGTH_LONG).show();
		return super.onKeyDown(keyCode, event);
	}

	public void onResume() {
		super.onResume();
	}

	@Override
	public void onConfigurationChanged(Configuration config) {
		super.onConfigurationChanged(config);
		WindowManager windowManager = getWindowManager();
		Display display = windowManager.getDefaultDisplay();
		int screenWidth = display.getWidth();
		int screenHeight = display.getHeight();

		if (m_myMapWnd != null) {
			m_myMapWnd.setSize(screenWidth, screenHeight);
			m_myMapWnd.reDraw();
			m_myMapWnd.repaint(0, 0);
			m_myMapWnd.invalidate();
		}
	}

	// 菜单
	public boolean onCreateOptionsMenu(android.view.Menu menu) {
		// 自定义的菜单
		// -------------------------------------------------------
		// 点选
		menu.add(0, Menu.FIRST + 1, Menu.NONE, "点选");
		// 矩形选
		menu.add(0, Menu.FIRST + 15, Menu.NONE, "矩形选");
		// 补偿漫游
		menu.add(0, Menu.FIRST + 11, Menu.NONE, "漫游");
		// 定位
		menu.add(0, Menu.FIRST + 28, Menu.NONE, "定位");
		// GPS
		menu.add(0, Menu.FIRST + 29, Menu.NONE, "GPS");
		// 全图显示
		menu.add(0, Menu.FIRST, Menu.NONE, "全图显示");

		// -------------------------------------------------------

		// SubMenu baseMenu = menu.addSubMenu("基本操作").setIcon(
		// android.R.drawable.ic_menu_myplaces);
		// baseMenu.add(0, Menu.FIRST + 9, Menu.NONE, "放大");
		// baseMenu.add(0, Menu.FIRST + 10, Menu.NONE, "缩小");
		// baseMenu.add(0, Menu.FIRST + 11, Menu.NONE, "补偿漫游");
		// baseMenu.add(0, Menu.FIRST + 12, Menu.NONE, "平滑漫游");
		// baseMenu.add(0, Menu.FIRST + 13, Menu.NONE, "旋转");
		// baseMenu.add(0, Menu.FIRST, Menu.NONE, "全图显示");

		// SubMenu selMenu = menu.addSubMenu("选取").setIcon(
		// android.R.drawable.ic_menu_crop);
		// selMenu.add(0, Menu.FIRST + 1, Menu.NONE, "点选");
		// selMenu.add(0, Menu.FIRST + 15, Menu.NONE, "矩形选");
		// selMenu.add(0, Menu.FIRST + 16, Menu.NONE, "多边形选");

		// SubMenu trackMenu = menu.addSubMenu("临时图层").setIcon(
		// android.R.drawable.ic_menu_mapmode);
		// trackMenu.add(0, Menu.FIRST + 2, Menu.NONE, "添加点");
		// trackMenu.add(0, Menu.FIRST + 3, Menu.NONE, "添加线");
		// trackMenu.add(0, Menu.FIRST + 4, Menu.NONE, "添加面");
		// trackMenu.add(0, Menu.FIRST + 14, Menu.NONE, "清空");

		// SubMenu queryMenu = menu.addSubMenu("查询").setIcon(
		// android.R.drawable.ic_menu_search);
		// queryMenu.add(0, Menu.FIRST + 6, Menu.NONE, "点查询");
		// queryMenu.add(0, Menu.FIRST + 7, Menu.NONE, "面查询");
		// queryMenu.add(0, Menu.FIRST + 8, Menu.NONE, "SQL查询");

		// menu.add(0, Menu.FIRST + 17, Menu.NONE, "图层管理器").setIcon(
		// android.R.drawable.ic_menu_slideshow);

		// SubMenu otherMenu = menu.addSubMenu("专题图").setIcon(
		// android.R.drawable.ic_menu_upload_you_tube);
		// otherMenu.add(0, Menu.FIRST + 18, Menu.NONE, "专题图");
		// otherMenu.add(0, Menu.FIRST + 19, Menu.NONE, "清空");

		// SubMenu cosmeticMenu = menu.addSubMenu("装饰图层").setIcon(
		// android.R.drawable.ic_menu_always_landscape_portrait);
		// cosmeticMenu.add(0, Menu.FIRST + 20, Menu.NONE, "添加点");
		// cosmeticMenu.add(0, Menu.FIRST + 21, Menu.NONE, "添加线");
		// cosmeticMenu.add(0, Menu.FIRST + 22, Menu.NONE, "添加面");
		// cosmeticMenu.add(0, Menu.FIRST + 23, Menu.NONE, "清空");
		// cosmeticMenu.add(0, Menu.FIRST + 24, Menu.NONE, "SQL查询");
		// cosmeticMenu.add(0, Menu.FIRST + 25, Menu.NONE, "查询");
		// cosmeticMenu.add(0, Menu.FIRST + 26, Menu.NONE, "删除");
		// cosmeticMenu.add(0, Menu.FIRST + 27, Menu.NONE, "添加自定义字段");

		return true;
	}

	// 菜单的单击事件
	public boolean onOptionsItemSelected(MenuItem item) {
		super.onOptionsItemSelected(item);
		switch (item.getItemId()) {// 获取菜单项的ID,即前面Menu.add方法的第二个参数
		case Menu.FIRST: {
			m_myMapWnd.viewEntire();
			m_myMapWnd.reDraw();
			m_myMapWnd.repaint(0, 0);

		}
			break;
		case Menu.FIRST + 1:
			// 点选
			m_myMapWnd.setTool(eMapAction.mcaSelectPoint);
			break;
		case Menu.FIRST + 2: {
			// TrackingLayer 添加点
			eMyGeometry geom = new eMyGeometry(1, 1);
			eMyPoint pt1 = m_myMapWnd.GetMap().GeoToMap(
					new eMyPoint2D(120.46, 36.0972));
			geom.SetPointAt(0, pt1);
			int type = 1;
			eMyStyle style = new eMyStyle();
			style.SetBmpIndex(40);
			String tag = "P1";
			m_myMapWnd.GetMap().TrackingLayer().AddEvent(geom, type, style,
					tag, 0);
			m_myMapWnd.GetMap().TrackingLayer().SetVisible(true);
			m_myMapWnd.repaint(0, 0);
		}
			break;
		case Menu.FIRST + 3: {
			// TrackingLayer 添加线
			eMyGeometry geom = new eMyGeometry(3, 1);
			eMyPoint pt1 = m_myMapWnd.GetMap().GeoToMap(
					new eMyPoint2D(120.4531, 36.0930));
			geom.SetPointAt(0, pt1);
			eMyPoint pt2 = m_myMapWnd.GetMap().GeoToMap(
					new eMyPoint2D(120.4664, 36.0901));
			geom.SetPointAt(1, pt2);
			eMyPoint pt3 = m_myMapWnd.GetMap().GeoToMap(
					new eMyPoint2D(120.4641, 36.0999));
			geom.SetPointAt(2, pt3);
			int type = 3;
			eMyStyle style = new eMyStyle();
			style.SetPenColor(Color.GREEN);
			style.SetPenWidth(3);
			String tag = "L1";
			m_myMapWnd.GetMap().TrackingLayer().AddEvent(geom, type, style,
					tag, 0);
			m_myMapWnd.GetMap().TrackingLayer().SetVisible(true);
			m_myMapWnd.repaint(0, 0);
		}
			break;
		case Menu.FIRST + 4: {
			// TrackingLayer 添加面
			eMyGeometry geom = new eMyGeometry(3, 1);
			eMyPoint pt1 = m_myMapWnd.GetMap().GeoToMap(
					new eMyPoint2D(120.4531, 36.0930));
			geom.SetPointAt(0, pt1);
			eMyPoint pt2 = m_myMapWnd.GetMap().GeoToMap(
					new eMyPoint2D(120.4614, 36.0981));
			geom.SetPointAt(1, pt2);
			eMyPoint pt3 = m_myMapWnd.GetMap().GeoToMap(
					new eMyPoint2D(120.4641, 36.0929));
			geom.SetPointAt(2, pt3);

			int type = 5;
			eMyStyle style = new eMyStyle();
			style.SetBrushColor(Color.RED);
			String tag = "A1";
			m_myMapWnd.GetMap().TrackingLayer().AddEvent(geom, type, style,
					tag, 0);
			m_myMapWnd.GetMap().TrackingLayer().SetVisible(true);
			m_myMapWnd.repaint(0, 0);

		}
			break;
		case Menu.FIRST + 5:
			System.exit(0);
			break;
		case Menu.FIRST + 7: {
			// 面查询
			eMyLayer lyr = m_myMapWnd.GetMap().GetLayerAt(2);
			if (lyr != null) {
				eMyRect bounds = new eMyRect(0, 0, 240, 320);
				eMyResultSet rs = lyr.QueryWithBounds(bounds);
				m_myMapWnd.GetMap().Selection().Add(rs);
				m_myMapWnd.repaint(0, 0);
			}
		}
			break;
		case Menu.FIRST + 8: {

			// SQL查询
			Intent intent = new Intent();

			intent.setClass(Demo.this, QueryUI.class);
			Bundle bundle = new Bundle();

			int c = m_myMapWnd.GetMap().GetLayerCount();
			String[] name = new String[c];
			for (short i = 0; i < c; i++) {
				name[i] = m_myMapWnd.GetMap().GetLayerAt(i).GetName();
			}

			bundle.putSerializable("layername", name);

			intent.putExtras(bundle);
			// @startActivity(intent);
			startActivityForResult(intent, QUERY);

			/*
			 * eMyLayer lyr = m_myMapWnd.GetMap().GetLayerAt(2); eMyResultSet rs
			 * = new eMyResultSet(); eMyQueryDefn qd = new eMyQueryDefn();
			 * qd.m_strWhereClause=" SID like '%67%'";
			 * qd.m_apFieldNames.add("类别码"); qd.m_apFieldNames.add("所在区");
			 * 
			 * eMyClauseDefn cDefn = new eMyClauseDefn(); cDefn.m_strWhereClause
			 * = " SID like '%67%'";
			 * 
			 * eMyStyle style = new eMyStyle(); style.SetBrushColor(Color.BLUE);
			 * cDefn.m_style =style; lyr.SetHighlightStyle(style);
			 * lyr.ThemeClause().AddClauseDefn(cDefn);
			 * lyr.ThemeClause().SetVisible(true); lyr.Query(qd, rs); String str
			 * = ""; while(rs.HasNext()){ str += rs.GetString(0); str +=
			 * rs.GetString(1); str += rs.GetString(2); str += rs.GetString(3);
			 * str += rs.GetString(4); str += rs.GetString(5);
			 * 
			 * } m_myMapWnd.GetMap().Selection().Add(rs);
			 * m_myMapWnd.repaint(0,0);
			 * Toast.makeText(this,str,Toast.LENGTH_SHORT).show();
			 */
		}
			break;
		case Menu.FIRST + 9: {
			// 放大
			// m_myMapWnd.ZoomByRatio(1.2);
			// m_myMapWnd.reDraw();
			// m_myMapWnd.repaint(0,0);
			m_myMapWnd.setTool(eMapAction.mcaZoomIn);
		}
			break;
		case Menu.FIRST + 10: {
			// 缩小
			// m_myMapWnd.ZoomByRatio(1/1.2);
			// m_myMapWnd.reDraw();
			// m_myMapWnd.repaint(0,0);
			m_myMapWnd.setTool(eMapAction.mcaZoomOut);
		}
			break;
		case Menu.FIRST + 11: {
			// 补偿漫游
			m_myMapWnd.setTool(eMapAction.mcaPan2);
		}
			break;
		case Menu.FIRST + 12: {
			// 平滑漫游
			m_myMapWnd.setTool(eMapAction.mcaPan);

		}
			break;
		case Menu.FIRST + 13: {
			// 旋转

			item.setCheckable(true);
			m_bRotate = !item.isChecked();
			item.setChecked(m_bRotate);
			if (!m_bRotate) {
				m_myMapWnd.SetRotateAngle(0);
				m_myMapWnd.reDraw();
				m_myMapWnd.repaint(0, 0);
			}

		}
			break;
		case Menu.FIRST + 14: {
			// 清空
			m_myMapWnd.GetMap().TrackingLayer().ClearEvents();
			m_myMapWnd.repaint(0, 0);
		}
			break;
		case Menu.FIRST + 15: {
			// 矩形选
			m_myMapWnd.setTool(eMapAction.mcaSelectRect);
		}
			break;
		case Menu.FIRST + 16: {
			// 多边形选
			m_myMapWnd.setTool(eMapAction.mcaSelectPolygon);
		}
			break;
		case Menu.FIRST + 17: {
			// 图层管理器
			Intent intent = new Intent();
			intent.setClass(Demo.this, layerControl.class);
			Bundle bundle = new Bundle();

			int c = m_myMapWnd.GetMap().GetLayerCount();
			String[] name = new String[c];
			boolean[] selectable = new boolean[c];
			for (short i = 0; i < c; i++) {
				name[i] = m_myMapWnd.GetMap().GetLayerAt(i).GetName();
				selectable[i] = m_myMapWnd.GetMap().GetLayerAt(i)
						.IsSelectable();
			}

			bundle.putSerializable("layername", name);
			bundle.putSerializable("selectable", selectable);
			intent.putExtras(bundle);
			startActivity(intent);

		}
			break;
		case Menu.FIRST + 18: {
			// 条件专题图
			eMyLayer layer = m_myMapWnd.GetMap().GetLayerAt(1);
			@SuppressWarnings("unused")
			String name = layer.GetName();
			eMyClauseDefn cd = new eMyClauseDefn();
			eMyStyle style = new eMyStyle();
			// style.SetPenColor(Color.RED);
			style.SetPenColor(255);
			style.SetPenWidth(5);
			style.SetPenStyle(11);
			cd.SetStyle(style);
			cd.SetName("1");
			cd.SetWhereClause("名称 LIKE '%海尔路%'");
			boolean b = layer.ThemeClause().AddClauseDefn(cd);
			if (b) {
				layer.ThemeClause().SetVisible(true);
				m_myMapWnd.reDraw();
				m_myMapWnd.repaint(0, 0);
			}

		}
			break;
		case Menu.FIRST + 19: {
			// 清空条件专题图
			eMyLayer layer = m_myMapWnd.GetMap().GetLayerAt(1);
			layer.ThemeClause().ClearClauseDefns();
			m_myMapWnd.reDraw();
			m_myMapWnd.repaint(0, 0);
		}
			break;
		case Menu.FIRST + 20: {
			// cometiclayer 添加点
			eMyGeometry geom = new eMyGeometry(1, 1);
			eMyPoint2D geoPt = new eMyPoint2D(120.46, 36.0972);
			eMyPoint pt = m_myMapWnd.GetMap().GeoToMap(geoPt);
			geoPt.Dispose();// 一定要调用Dispose销毁对象,否则会照成内存泄露!
			geom.SetPointAt(0, pt);
			@SuppressWarnings("unused")
			int type = 1;
			eMyStyle style = new eMyStyle();
			style.SetBmpIndex(3);
			@SuppressWarnings("unused")
			String tag = "A1";
			/*
			 * int stmt = m_myMapWnd.GetMap().CosmeticLayer().Add();
			 * m_myMapWnd.GetMap().CosmeticLayer().Set(stmt, geom, type, style,
			 * tag, "text"); m_myMapWnd.GetMap().CosmeticLayer().Update(stmt);
			 * m_myMapWnd.GetMap().CosmeticLayer().SetVisible(true);
			 * m_myMapWnd.reDraw(); m_myMapWnd.repaint(0, 0);
			 */
		}
			break;
		case Menu.FIRST + 21: {
			/*
			 * //cometiclayer 添加线 eMyGeometry geom = new eMyGeometry();
			 * geom.m_sPartCount = 1; geom.m_sPointCount = 3; geom.m_pPoints =
			 * new eMyPoint[3]; eMyPoint pt1 = m_myMapWnd.GetMap().GeoToMap(new
			 * eMyPoint2D(120.4531,36.0930)); geom.m_pPoints[0] = new
			 * eMyPoint(); geom.m_pPoints[0].x = pt1.x; geom.m_pPoints[0].y =
			 * pt1.y; eMyPoint pt2 = m_myMapWnd.GetMap().GeoToMap(new
			 * eMyPoint2D(120.4614,36.0981)); geom.m_pPoints[1] = new
			 * eMyPoint(); geom.m_pPoints[1].x = pt2.x; geom.m_pPoints[1].y =
			 * pt2.y; eMyPoint pt3 = m_myMapWnd.GetMap().GeoToMap(new
			 * eMyPoint2D(120.4641,36.0929)); geom.m_pPoints[2] = new
			 * eMyPoint(); geom.m_pPoints[2].x = pt3.x; geom.m_pPoints[2].y =
			 * pt3.y; int type = 3; eMyStyle style = new eMyStyle();
			 * style.SetBrushColor(Color.RED); style.SetPenColor(Color.GREEN);
			 * style.SetPenWidth(5); style.SetPenStyle(1);
			 * style.SetBmpOffsetX(88); style.SetBmpOffsetY(88); String tag =
			 * "A3"; SQLiteStatement stmt =
			 * m_myMapWnd.GetMap().CosmeticLayer().add();
			 * m_myMapWnd.GetMap().CosmeticLayer().Set(stmt, geom, type, style,
			 * tag, "text"); m_myMapWnd.GetMap().CosmeticLayer().Set(stmt,
			 * "mobile", 54321); m_myMapWnd.GetMap().CosmeticLayer().Set(stmt,
			 * "label", "美国改革开放");
			 * m_myMapWnd.GetMap().CosmeticLayer().Update(stmt);
			 * m_myMapWnd.GetMap().CosmeticLayer().SetVisible(true);
			 * m_myMapWnd.reDraw(); m_myMapWnd.repaint(0, 0);
			 */
		}
			break;
		case Menu.FIRST + 22: {
			/*
			 * //cometiclayer 添加面 eMyGeometry geom = new eMyGeometry();
			 * geom.m_sPartCount = 1; geom.m_sPointCount = 3; geom.m_pPoints =
			 * new eMyPoint[3]; eMyPoint pt1 = m_myMapWnd.GetMap().GeoToMap(new
			 * eMyPoint2D(120.4531,36.0930)); geom.m_pPoints[0] = new
			 * eMyPoint(); geom.m_pPoints[0].x = pt1.x; geom.m_pPoints[0].y =
			 * pt1.y; eMyPoint pt2 = m_myMapWnd.GetMap().GeoToMap(new
			 * eMyPoint2D(120.4614,36.0981)); geom.m_pPoints[1] = new
			 * eMyPoint(); geom.m_pPoints[1].x = pt2.x; geom.m_pPoints[1].y =
			 * pt2.y; eMyPoint pt3 = m_myMapWnd.GetMap().GeoToMap(new
			 * eMyPoint2D(120.4641,36.0929)); geom.m_pPoints[2] = new
			 * eMyPoint(); geom.m_pPoints[2].x = pt3.x; geom.m_pPoints[2].y =
			 * pt3.y; int type = 5; eMyStyle style = new eMyStyle();
			 * style.SetBrushColor(Color.RED); style.SetBmpOffsetX(88);
			 * style.SetBmpOffsetY(88); String tag = "A5"; eMyCosmeticLayer cl =
			 * m_myMapWnd.GetMap().CosmeticLayer(); SQLiteStatement stmt =
			 * cl.add(); cl.Set(stmt, geom, type, style, tag, "text");
			 * cl.Set(stmt, "mobile", 12345); cl.Set(stmt, "label", "中国改革开放");
			 * cl.Update(stmt); cl.SetVisible(true); m_myMapWnd.reDraw();
			 * m_myMapWnd.repaint(0, 0);
			 */
		}
			break;
		case Menu.FIRST + 23: {
			/*
			 * //cometiclayer 清空
			 * m_myMapWnd.GetMap().CosmeticLayer().removeAll();
			 * m_myMapWnd.reDraw(); m_myMapWnd.repaint(0, 0);
			 */
		}
			break;
		case Menu.FIRST + 24: {
			/*
			 * //cometiclayer SQL查询 eMyQueryDefn queryDefn = new eMyQueryDefn();
			 * //queryDefn.AddSelectField("label");
			 * //queryDefn.AddSelectField("moible");
			 * queryDefn.SetWhereClause("label like '%美国%'");
			 * eMyCosmeticResultSet rs = new eMyCosmeticResultSet();
			 * m_myMapWnd.GetMap().CosmeticLayer().Query(queryDefn, rs);
			 * while(rs.HasNext()){ String label = rs.GetText("label"); int
			 * mobile = rs.GetInt("mobile"); mobile = 1; }
			 */
		}
			break;
		case Menu.FIRST + 25: {
			/*
			 * //cometiclayer 空间查询 eMyRect2D bounds =
			 * m_myMapWnd.GetMap().GetGeoBounds(); eMyCosmeticResultSet rs = new
			 * eMyCosmeticResultSet();
			 * m_myMapWnd.GetMap().CosmeticLayer().QueryWithBounds(bounds, rs);
			 * while(rs.HasNext()){ eMyGeometry geom = rs.GetGeometry(); }
			 * rs.Close();
			 * 
			 * m_myMapWnd.reDraw(); m_myMapWnd.repaint(0, 0);
			 */
		}
			break;
		case Menu.FIRST + 26:
			//		
		{
			/*
			 * //cometiclayer 删除 m_myMapWnd.GetMap().CosmeticLayer().Delete();
			 * m_myMapWnd.reDraw(); m_myMapWnd.repaint(0, 0);
			 */
		}
			break;
		case Menu.FIRST + 27:
			//		
		{
			/*
			 * //cometiclayer 添加自定义字段 eMyCosmeticField fld = new
			 * eMyCosmeticField("label","TEXT"); eMyCosmeticField fld2 = new
			 * eMyCosmeticField("mobile","NUMERIC");
			 * 
			 * m_myMapWnd.GetMap().CosmeticLayer().addCustomFields(fld);
			 * m_myMapWnd.GetMap().CosmeticLayer().addCustomFields(fld2);
			 * m_myMapWnd.reDraw(); m_myMapWnd.repaint(0, 0);
			 */
		}
			break;
		case Menu.FIRST + 28:
			// 定位到某个点
		{
			// 测试定位数据
			// 边际物理坐标:( 120.46245999981475) , (36.101044000086 )
			// 中心物理坐标:( 120.45992200009175) , (36.095697000196125 )
			// 测试物理坐标:( 120.46158699979) , (36.09769800014725 )
			loc_x = 120.46158699979;
			loc_y = 36.09769800014725;
			m_myMapWnd.ZoomTo(loc_x, loc_y, 0.002);// 0.02 小 0.002 大 0.011 适中
			m_myMapWnd.reDraw();// 那个Ondraw在redraw就会触发
			m_myMapWnd.repaint(0, 0);
			Toast.makeText(this, "定位", 6000).show();
		}
			break;
		case Menu.FIRST + 29: {
			// 获得GPS数据
			showGPSDate(getGPSDate(), 1);
			GPSModel gpsModel = new GPSModel();
			gpsModel = getGPSDate();
			loc_x = gpsModel.Longitude;
			loc_y = gpsModel.Latitude;
			// 定位到该点
			m_myMapWnd.ZoomTo(loc_x, loc_y, 0.002);
			m_myMapWnd.reDraw();// 那个Ondraw在redraw就会触发
			m_myMapWnd.repaint(0, 0);

			Toast.makeText(this, "GPS", 6000).show();
		}
			break;
		}

		return true;
	}

	// 显示方法
	public void show(int i, String name, String id, String city, String area,
			String category, String geocode, double x, double y) {
		String text = "";
		int j = i + 1;
		// System.out.println("---------" + j + "---------");
		// String xy = "物理坐标:(" + x + "),(" + y + ")";
		// System.out.println(xy);
		// System.out.println("名称:" + name);
		// System.out.println("ID:" + id);
		// System.out.println("城市:" + city);
		// System.out.println("所在区:" + area);
		// System.out.println("类别码:" + category);
		// System.out.println("地理编码:" + geocode);
		// System.out.println("---------------------------------");

		text += "名称:" + name + "\n";
		text += "ID:" + id + "\n";
		text += "城市:" + city + "\n";
		text += "所在区:" + area + "\n";
		text += "类别码:" + category + "\n";
		text += "地理编码:" + geocode + "\n";
		text += "物理坐标:(" + x + "),(" + y + ")" + "\n";
		Toast.makeText(Demo.this, text, 5000).show();
	}

	// 显示信息
	private void showGPSDate(GPSModel gpsModel, int infotype) {
		// GPS功能已关闭
		if (gpsModel == null) {
			if (infotype == -1) {
				Toast.makeText(this, "GPS功能已关闭,请打开后重试!", 3000).show();
			}
		} else {
			double y = gpsModel.Latitude;// 纬度
			double x = gpsModel.Longitude;// 经度
			String text = "";
			text += "经度X=" + String.valueOf(x) + "\n";
			text += "经度Y=" + String.valueOf(y) + "\n";
			gpsModel.InfoType = infotype;
			switch (infotype) {
			case 1:
				text += "获取方式=手动获取更新" + "\n";
				Toast.makeText(this, text, 5000).show();
				break;
			case 2:
				text += "获取方式=位置改变更新" + "\n";

				// 模拟器测试:发送GPS坐标==============
				// GPSModel gpsModel2 = new GPSModel();
				// gpsModel2 = getGPSDate();
				// loc_x = gpsModel2.Longitude;
				// loc_y = gpsModel2.Latitude;
				// m_myMapWnd.ZoomTo(loc_x, loc_y, 0.002);
				// m_myMapWnd.reDraw();// 那个Ondraw在redraw就会触发
				// m_myMapWnd.repaint(0, 0);
				// ===================================

				Toast.makeText(this, text, 5000).show();
				break;
			}
		}

	}

	// 获取GPS相应的数据
	private GPSModel getGPSDate() {
		GPSModel gpsModel = new GPSModel();
		location = locationManager.getLastKnownLocation(provider);
		if (location != null) {
			gpsModel.Latitude = (double) (location.getLatitude());
			gpsModel.Longitude = (double) (location.getLongitude());
			gpsModel.High = location.getAltitude();
			gpsModel.Direct = location.getBearing();
			gpsModel.Speed = location.getSpeed();

			Date d = new Date();
			d.setTime(location.getTime());
			gpsModel.GpsTime = DateFormat.format("yyyy-MM-dd kk:mm:ss", d)
					.toString();
			d = null;
		}
		return gpsModel;
	}

	private final LocationListener locationListener = new LocationListener() {
		public void onLocationChanged(Location arg0) {
			showGPSDate(getGPSDate(), 2);// 位置改变

		}

		public void onProviderDisabled(String arg0) {
			showGPSDate(null, -1);
		}

		public void onProviderEnabled(String arg0) {
		}

		public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
		}

	};

}

 

你可能感兴趣的:(demo)