作者:程溯

简介

Demo按类型往地图里添加POI兴趣点,并添加兴趣点的名称(name)与详细信息(detail)。地图上不同类型的POI兴趣点采用不同符号来表示。

示例数据

Data: mypoi.udb、mypoi.udd、mypoi.smwu

关键类型/成员

GeoStyle类

GeoPoint类

Environment类

WorkspaceConnectionInfo类

Map.setWorkspace()方法

MapControl.addGeometryAddedListener()方法

DatasetVector.query()方法

Recordset.edit()方法

Recordset.setGeometry()类

Recordset.setFieldValue()方法

Recordset.update()方法

使用步骤

(1) 将iMobile for android根目录的libs目录下的armeabi目录、com.supermap.data.jar、
com.supermap.mapping.jar拷贝至MyPoi工程目录的libs目录。
(2) elcipse导入MyPoi工程,如果需要,修改工程属性。
(3)需要将数据文件拷贝至android手机或模拟器的指定目录下。
(4) 编译运行程序,通过类型下拉列表选择POI类型,单击“添加”按钮,设置添加操作状态。
(5) 在地图上需要的位置单击,添加兴趣点,添加之后再单击“提交”按钮,提交操作。 在弹出的页面中填写名称和详细信息,单击“添加”按钮返回地图页面,地图窗口中显示了POI的符号和名称。

代码块

MainActivity:


import com.supermap.data.*;
import com.supermap.mapping.*;
import com.supermap.test.R;import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.ZoomControls;public class MainActivity extends Activity implements OnTouchListener,GeometryAddedListener {private final int REQUEST_INFO = 1001;private MapControl mapControl;private Workspace workspace;private MapView mapView;private ZoomControls zoomControls;private Spinner spinnerPoiType;private Button addButton;private Button add;private DatasetVector datasetVector;private String strSymbolName = "银行";private int nSymbolID = 907971;private GeometryEvent curEvent;private static final String[] types = { "银行", "医院", "小区", "停车场", "商场","公园", "药店", "小区", "餐厅" };@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);Environment.setLicensePath(getString(R.string.license_path));Environment.setTemporaryPath(getString(R.string.temp_path));Environment.setWebCacheDirectory(getString(R.string.cache_path));Environment.initialization(this);setContentView(R.layout.main);openData();initView();}private void openData() {workspace = new Workspace();WorkspaceConnectionInfo info = new WorkspaceConnectionInfo();info.setServer(getString(R.string.data_path));info.setType(WorkspaceType.SMWU);if (workspace.open(info)) {mapView = (MapView) findViewById(R.id.mapview);mapControl = mapView.getMapControl();mapControl.getMap().setWorkspace(workspace);boolean isOpenMap = mapControl.getMap().open("map");if (isOpenMap) {mapControl.addGeometryAddedListener(this);mapControl.getMap().refresh();Layer layer = mapControl.getMap().getLayers().get(1);layer.setEditable(true);Dataset dataset = workspace.getDatasources().get(0).getDatasets().get(0);if (dataset != null) {datasetVector = (DatasetVector) dataset;}}}}private void initView() {add = (Button) findViewById(R.id.add);zoomControls = (ZoomControls) findViewById(R.id.zoomControls1);zoomControls.setOnZoomOutClickListener(new OnClickListener() {public void onClick(View v) {mapControl.getMap().zoom(0.5);mapControl.getMap().refresh();}});zoomControls.setOnZoomInClickListener(new OnClickListener() {public void onClick(View v) {mapControl.getMap().zoom(2);mapControl.getMap().refresh();}});addButton = (Button) findViewById(R.id.btn_add);addButton.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {mapControl.setAction(Action.CREATEPOINT);}});spinnerPoiType = (Spinner) findViewById(R.id.spn_poi_type);ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item, types);adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);spinnerPoiType.setAdapter(adapter);spinnerPoiType.setOnItemSelectedListener(new OnItemSelectedListener() {public void onItemSelected(AdapterView<?> arg0, View arg1,int arg2, long arg3) {if (spinnerPoiType.getSelectedItem() != null) {strSymbolName = spinnerPoiType.getSelectedItem().toString();}strSymbolName = spinnerPoiType.getSelectedItem().toString();if (strSymbolName.equals("")) {return;} else {Symbol symbol = workspace.getResources().getMarkerLibrary().findSymbol(strSymbolName);if (symbol != null) {nSymbolID = symbol.getID();} else {nSymbolID = 0;}}}public void onNothingSelected(AdapterView<?> arg0) {}});}public void add(View view) {mapControl.submit();}@Overridepublic void geometryAdded(GeometryEvent arg0) {curEvent = arg0;Intent intent = new Intent(getBaseContext(), InfoWnd.class);intent.putExtra(InfoWnd.Poi_Type, strSymbolName);startActivityForResult(intent, REQUEST_INFO);}public synchronized void onActivityResult(final int requestCode,int resultCode, final Intent data) {if (resultCode == Activity.RESULT_OK) {if (requestCode == REQUEST_INFO) {String strName = data.getStringExtra(InfoWnd.INFO_NAME);String strDetail = data.getStringExtra(InfoWnd.INFO_DETAIL);setPointInfo(strName, strDetail);}} else {deletePoint();}mapControl.getMap().refresh();mapControl.setAction(Action.PAN);}private void setPointInfo(String strName, String strDetail) {try {if (datasetVector == null) {return;}String strFilter = "SmID = " + String.valueOf(curEvent.getID());Recordset recordset = null;recordset = datasetVector.query(strFilter, CursorType.DYNAMIC);Geometry geometry = recordset.getGeometry();GeoPoint geoPoint = null;if (geometry != null) {geoPoint = (GeoPoint) geometry;GeoStyle geoStyle = new GeoStyle();geoStyle.setMarkerSize(new Size2D(8, 8));geoStyle.setMarkerSymbolID(nSymbolID);geoPoint.setStyle(geoStyle);}recordset.edit();if (geoPoint != null) {recordset.setGeometry(geoPoint);}if (!strName.isEmpty()) {recordset.setFieldValue("name", strName);}if (!strDetail.isEmpty()) {recordset.setFieldValue("detail", strDetail);}recordset.update();recordset.dispose();mapControl.getMap().refresh();} catch (Exception e) {Log.e("MyPoit", e.getMessage());}}private void deletePoint() {if (datasetVector == null) {return;}String strFilter = "SmID = " + String.valueOf(curEvent.getID());Recordset recordset = null;recordset = datasetVector.query(strFilter, CursorType.DYNAMIC);recordset.delete();recordset.dispose();}public boolean onTouch(View v, MotionEvent event) {mapControl.onMultiTouch(event);return true;}public void onDestroy() {workspace.close();super.onDestroy();}
}

InfoWnd:

import com.supermap.test.R;import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.*;public class InfoWnd extends Activity implements OnClickListener{public static final String Poi_Type = "PoiType";public static final String INFO_NAME = "Name";public static final String INFO_DETAIL = "Detail";private EditText etName;private EditText etDetail;private Button btnAdd;private Button btnCancel;@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.infownd);etName = (EditText) findViewById(R.id.editName);etDetail = (EditText) findViewById(R.id.editDetail);btnAdd = (Button) findViewById(R.id.btn_add);btnAdd.setOnClickListener(this);btnCancel = (Button) findViewById(R.id.btn_cancel);btnCancel.setOnClickListener(this);etName = (EditText)findViewById(R.id.editName);etDetail = (EditText)findViewById(R.id.editDetail);String strName = getIntent().getStringExtra(Poi_Type);      etName.setText(strName);}@Overrideprotected void onDestroy() {super.onDestroy();}public void onClick(View view) {if (view == btnAdd) {addPoint();} else if (view == btnCancel) {finish();}}private void addPoint() {String strName = etName.getText().toString();String strDetail = etDetail.getText().toString();getIntent().putExtra(INFO_NAME, strName);getIntent().putExtra(INFO_DETAIL, strDetail);setResult(RESULT_OK, getIntent());finish();}
}

main.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"android:layout_height="fill_parent"android:orientation="vertical" ><RelativeLayoutandroid:id="@+id/map_panel"android:layout_width="fill_parent"android:layout_height="wrap_content" ><com.supermap.mapping.MapViewandroid:id="@+id/mapview"android:layout_width="fill_parent"android:layout_height="fill_parent" ></com.supermap.mapping.MapView><ZoomControlsandroid:id="@+id/zoomControls1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentBottom="true"android:layout_alignParentRight="true" /></RelativeLayout><RelativeLayoutandroid:id="@+id/toolbar"android:layout_width="fill_parent"android:layout_height="wrap_content"android:layout_margin="6dp"android:background="@drawable/toolbar_selector"android:paddingBottom="2dp"android:paddingLeft="6dp"android:paddingRight="6dp"android:paddingTop="6dp" ><TextViewandroid:id="@+id/txt_poi_type"android:layout_width="wrap_content"android:layout_height="40dp"android:layout_alignParentLeft="true"android:gravity="center"android:text="@string/poitype"android:textColor="#ff000000" /><Spinnerandroid:id="@+id/spn_poi_type"android:layout_width="fill_parent"android:layout_height="40dp"android:layout_toLeftOf="@+id/btn_add"android:layout_toRightOf="@+id/txt_poi_type" /><Buttonandroid:id="@+id/btn_add"android:layout_width="52dp"android:layout_height="40dp"android:layout_toLeftOf="@+id/add"android:text="@string/stradd" /><Buttonandroid:id="@+id/add"android:layout_width="52dp"android:layout_height="40dp"android:layout_alignParentRight="true"android:onClick="add"android:text="提交" /></RelativeLayout></RelativeLayout>

infownd.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"android:layout_height="fill_parent"android:orientation="vertical" ><EditTextandroid:id="@+id/editName"android:layout_width="fill_parent"android:layout_height="wrap_content"android:hint="@string/inputname" /><EditTextandroid:id="@+id/editDetail"android:layout_width="fill_parent"android:layout_height="100dp"android:hint="@string/inputdetail"android:scrollbars="vertical" /><LinearLayoutandroid:id="@+id/linearLayout1"android:layout_width="fill_parent"android:layout_height="wrap_content" ><Buttonandroid:id="@+id/btn_add"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/stradd" /><Buttonandroid:id="@+id/btn_cancel"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/strcancel" /></LinearLayout></LinearLayout>

运行效果

SuperMap iMobile for Android 地图添加POI兴趣点相关推荐

  1. SuperMap iMobile for Android 地图开发(一)

    第一步:创建 Android Studio 项目 第一步:创建 Android Studio 项目 Android Studio 有两种创建项目的方法. 第一种是在 Android Studio起始页 ...

  2. SuperMap iMobile for Android 地图开发在线地图服务接入(二)

    一.对接百度地图服务 DatasourceConnectionInfo info = new DatasourceConnectionInfo(); //设置数据源别名 info.setAlias(& ...

  3. SuperMap iMobile for Android常见问题解答集锦(十四)

    问:SuperMap iMobile for Android中导出shp数据时能否设置其字符集,怎么设置? 答:导出时可以设置shp的字符集,通过类DataConversion下的setConvert ...

  4. SuperMap iMobile for Android常见问题解答集锦(十三)

    作者:皇皇 问:SuperMap iMobile for Android中是否支持实时GPS定位,怎么实现? 答:可以支持:通过LocationManagePlugin管理插件类,开启GPS设备,并设 ...

  5. SuperMap iMobile for Android之行业导航

    作者 :dongyx 在我们工作生活中,经常会遇到怎么去哪.如何去最节约成本的问题,这就需要使用地图导航的功能了,那么如何使用SuperMap iMobile for Android制作导航APP呢? ...

  6. SuperMap iMobile for Android中三维AR的使用

    前言 ARCore是一种增强现实体验构建平台,它可以利用不同的API让手机能够感知其环境.理解现实世界与信息进行交互.ARCore使用三个主要功能将虚拟内容与通过手机摄像头看到的现实世界整合: 1) ...

  7. SuperMap iMobile for Android许可介绍

    作者:dongyx 使用SuperMap iMobile产品需要SuperMap的授权,即获得许可.目前,针对不同的用户和不同的使用场景,SuperMap iMobile提供三种许可方式,分别为试用许 ...

  8. SuperMap iMobile 8Cfor Android/iOS ——专业级移动GIS开发平台

    SuperMap iMobile 8C是一款全新的移动GIS开发平台,具备专业.全面的移动GIS功能.支持基于Android和iOS操作系统的智能移动终端,可以快速开发在线和离线的移动GIS应用. 谁 ...

  9. SuperMap iMobile for Android开发入门(iMobile 10i + AS 3.6)

    SuperMap iMobile开发入门(iMobile 10i + AS3.6) 超图防坑指南 文章概要 AS3.6安装.SuperMap iMobile 10i下载 HelloMap工程创建 He ...

最新文章

  1. PacBio单分子长测序
  2. 〖Android〗从Android Studio转为Eclipse开发项目运行程序闪退的解决方法
  3. 程序员如何解决工作中的技术问题?
  4. 082_html5Web存储
  5. stacking与blending的区别
  6. Statement, PreparedStatement和CallableStatement的区别
  7. echarts 地图实现轮播(二)
  8. 使用MetaPost绘制流程图
  9. careercup-递归和动态规划 9.2
  10. 软件测试核心之用例设计
  11. EXPRESS项目PM2启动NODE_ENV传参数不生效问题解决方法
  12. PHP入门part1
  13. docker安装redis,使用jedis轻松操作redis
  14. sql判断时间大于0点_Java秒杀系统实战系列-数据库级别Sql的优化与代码的调整
  15. 基于Python-turtle库绘图(汇总)
  16. 2.1 CMMI2级——7个PA简述
  17. pyqtsignal()作用
  18. OpenCV | 训练识别狗的分类器过程详解
  19. cf两边黑屏怎么解决win10_win10玩红警卡顿黑屏,这样解决,有些老游戏也可以借鉴哦
  20. 百度地图显示车辆运行轨迹(动态轨迹回放功能)

热门文章

  1. 如何在Google日历中显示Outlook日历
  2. Uestc1291 上天的卿学姐【状压dp】
  3. 信息安全数学基础 Chapter 1——整除
  4. mysql在哪执行sql语句_mysql从命令行执行sql语句
  5. python爬虫六:爬取电影图片及简介
  6. x5-fullscreen_HTML5 FullScreen API简介
  7. python rowcount_如何在ponyorm中创建rowcount?Python
  8. Unittest单元测试总结
  9. oracle的wallet是什么意思,oracleWallet的使用
  10. 开发笔记4——钱包、账户、keyeos、nodeos、cleos概念介绍