arcgis for android API包 里有一些例子,建议先打开hello World示例看看。我就是看了点例子,然后从网上的高人们的blog里找资料学习的。

先让我们来做个示例。如果不让我看到点成就的页面,我怕觉得自己没掌握到任何东西。

下面是我个人的一些理解:

1.MapView 是android中的以个viewGroup对象,它继承具有viewGroup的属性。它是地图视图的主面板。或者说是一个地图视图的入口。

2. 我们可以往MapView 下(内)添加多个图层(layer)。

MapView map;

map.addLayer(...)

3.我们可以构建一些地图服务图层对象。该服务需要一个URL的服务地址。

new com.esri.android.map.ags.ArcGISTiledMapServiceLayer(

"http://cache1.arcgisonline.cn/ArcGIS/rest/services/ChinaCities_Community_BaseMap_ENG/BeiJing_Community_BaseMap_ENG/MapServer")

这里构建以个ArcGISTiledMapServiceLayer对象。

4.添加图层。并将该“服务图层”附件到mapView以下。

ArcGISTiledMapServiceLayeragmServiceLayer;

map.addLayer(agmServiceLayer)

4. mapView可以指定一个坐标位置。该坐标位置确定了“要显示地图的范围区域”。

Envelope initextext = new Envelope(12899459.4956466,4815363.65520802,13004178.2243971,4882704.67712717);//这里有4个坐标点,看似是一个矩形的4个顶点。

map.setExtent(initextext);//设定。。。

好吧,让我们跑起来代码。

-----------

贴完整代码如下:

布局:

<?xmlversion="1.0"encoding="utf-8"?>

< LinearLayout xmlns:android ="http://schemas.android.com/apk/res/android"
android:layout_width
="fill_parent"
android:layout_height
="fill_parent"
android:orientation
="vertical" >

< LinearLayout
android:layout_width ="fill_parent"
android:layout_height
="wrap_content" >

< Button
android:id ="@+id/btnToBeijing"
android:layout_width
="wrap_content"
android:layout_height
="wrap_content"
android:text
="到北京" />

< Button
android:id ="@+id/btnToShenyang"
android:layout_width
="wrap_content"
android:layout_height
="wrap_content"
android:text
="到沈阳" />
</ LinearLayout >

<!-- MapViewlayoutandinitialextent -->

< com.esri.android.map.MapView
android:id ="@+id/map"
android:layout_width
="fill_parent"
android:layout_height
="fill_parent" >
</ com.esri.android.map.MapView >

</ LinearLayout >

代码:

/*Copyright2012ESRI

*
*AllrightsreservedunderthecopyrightlawsoftheUnitedStates
*andapplicableinternationallaws,treaties,andconventions.
*
*Youmayfreelyredistributeandusethissamplecode,withor
*withoutmodification,providedyouincludetheoriginalcopyright
*noticeanduserestrictions.
*
*Seethe�Samplecodeusagerestrictions�documentforfurtherinformation.
*
*/

packagecom.esri.arcgis.android.samples.helloworld;

importandroid.app.Activity;
importandroid.os.Bundle;
importandroid.view.View;
importandroid.view.View.OnClickListener;
importandroid.widget.Button;

importcom.esri.android.map.MapView;
importcom.esri.android.map.ags.ArcGISDynamicMapServiceLayer;
importcom.esri.android.map.ags.ArcGISTiledMapServiceLayer;
importcom.esri.core.geometry.Envelope;
importcom.esri.core.geometry.Geometry;

public classHelloWorld extendsActivity{
MapViewmap= null;
ArcGISTiledMapServiceLayertileLayer;
Buttonm_btnToShenyang;
Buttonm_btnToBeijing;

/** Calledwhentheactivityisfirstcreated. */
public voidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

m_btnToShenyang=(Button)findViewById(R.id.btnToShenyang);
m_btnToShenyang.setOnClickListener( newOnClickListener(){

@Override
public voidonClick(Viewarg0){
// AdddynamiclayertoMapView
map.addLayer( newcom.esri.android.map.ags.ArcGISTiledMapServiceLayer(""+
"http://cache1.arcgisonline.cn/ArcGIS/rest/services/ChinaCities_Community_BaseMap_ENG/ShenYang_Community_BaseMap_ENG/MapServer"));

Envelopeinitextext= newEnvelope(13700260.2294766,5108777.85728174,13769970.7992726,5150359.60066882);
map.setExtent(initextext);
}
});

m_btnToBeijing=(Button)findViewById(R.id.btnToBeijing);
m_btnToBeijing.setOnClickListener( newOnClickListener(){

@Override
public voidonClick(Viewarg0){
// AdddynamiclayertoMapView
map.addLayer( newcom.esri.android.map.ags.ArcGISTiledMapServiceLayer(""+
"http://cache1.arcgisonline.cn/ArcGIS/rest/services/ChinaCities_Community_BaseMap_ENG/BeiJing_Community_BaseMap_ENG/MapServer"));

Envelopeinitextext= newEnvelope(12899459.4956466,4815363.65520802,13004178.2243971,4882704.67712717);
map.setExtent(initextext);
}
});

// RetrievethemapandinitialextentfromXMLlayout
map=(MapView)findViewById(R.id.map);
// AddtiledlayertoMapView
tileLayer= newArcGISTiledMapServiceLayer("http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer");
map.addLayer(tileLayer);
Envelopeinitextext= newEnvelope(-20037507.0671618,-20037507.0671618,20037507.0671618,20037507.0671619);
map.setExtent(initextext);
}




protected voidonPause(){
super.onPause();
map.pause();
}

protected voidonResume(){
super.onResume();
map.unpause();
}

}

参考:

sydbc的博客:http://www.gisall.com/html/72/124272-6268.html

更多相关文章

  1. 类和 Json对象
  2. 浅析android通过jni控制service服务程序的简易流程
  3. Android(安卓)Service AIDL
  4. android用户界面-组件Widget-地图视图MapView
  5. Android中文API(144) —— JsonWriter
  6. Android之Handler用法总结
  7. Android架构分析之使用自定义硬件抽象层(HAL)模块
  8. android通过ksoap2对webservice的解析
  9. Android(安卓)View的介绍和使用

随机推荐

  1. Android(安卓)TextView中android:textIsS
  2. Flutter 与 Android(安卓)相互调用、传递
  3. android 百度地图SDK 获得详细路线信息
  4. android Widget-显示电量
  5. android避免decodeResource图片时占用太
  6. Android(安卓)简易对话框
  7. android发送json并解析返回json
  8. Android(安卓)各尺寸单位间的换算
  9. Android简易闹钟实现
  10. Android(安卓)之 Spinner用法介绍