refly1989
路人甲
路人甲
  • 注册日期2015-10-28
  • 发帖数1
  • QQ
  • 铜币1枚
  • 威望1点
  • 贡献值0点
  • 银元0个
阅读:1702回复:1

ArcGis Runtime For Android使用离线底图撒点无法展示

楼主#
更多 发布于:2015-10-28 11:45
如题,项目中使用arcgis android开发包,创建了后缀名为tpk的离线底图,然后在底图上画了一个点,怎么都显示不出来。可是如果我不用离线底图,调用Rest切片服务的话则可以显示在地图上。两种方法使用的地图数据都是同一个。请问这是什么原因?
喜欢0 评分0
gis
gis
管理员
管理员
  • 注册日期2003-07-16
  • 发帖数15947
  • QQ554730525
  • 铜币25339枚
  • 威望15364点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • 帝国沙发管家
  • GIS帝国明星
  • GIS帝国铁杆
1楼#
发布于:2015-10-28 11:50
本实例主要是针对四川地理信息中心的切片,如果利用ArcGIS for Android API进行解析,并读入作用底图。
1)基础准备:下载Java版的Json解析库(http://code.google.com/p/json-simple/)、熟悉四川地理信息中心切片规则
2)关于四川地理信息中心的切片规则这就不做介绍了,在以前专题已介绍过,详见:http://www.scgis.net/
3)代码说明
AgsLOD.java:切片等级信息定义文件,在这定义了比例尽、等级、分辨率



[java] view plaincopy

  1. package com.esri.arcgis.android.samples;  
  2.  
  3. import com.esri.core.internal.d.c;  
  4.  
  5. public class AgsLOD extends c {  
  6. private static final long serialVersionUID = 4341699179151728883L;  
  7.      
  8.    private int level;  
  9.    private double resolution;  
  10.    private double scale;  
  11.  
  12.    public AgsLOD(int level, double scale, double resolution) {  
  13.    super();  
  14.  
  15.    this.level = level;  
  16.    this.scale = scale;  
  17.    this.resolution = resolution;  
  18.    }  
  19.  
  20.    public int a() {  
  21.    return this.level;  
  22.    }  
  23.  
  24.    public double b() {  
  25.    return this.resolution;  
  26.    }  
  27.  
  28.    public double c() {  
  29.    return this.scale;  
  30.    }  
  31. }  
GetToken.java:通过Web请求提交用户名跟密码,获取Token字符口串,并对字符串进行解析,用于获取地图切片。





[java] view plaincopy

  1. package com.esri.arcgis.android.samples;  
  2.  
  3. import java.io.BufferedReader;  
  4. import java.io.InputStreamReader;  
  5. import java.net.HttpURLConnection;  
  6. import java.net.URL;  
  7.  
  8. public class GetToken {  
  9.    //get token  
  10.    public String sendPost(String url) {    
  11.        StringBuilder result = new StringBuilder();    
  12.        try {    
  13.            URL httpurl = new URL(url);    
  14.            HttpURLConnection httpConn = (HttpURLConnection) httpurl    
  15.                    .openConnection();    
  16.            httpConn.setDoInput(true);    
  17.            BufferedReader in = new BufferedReader(new InputStreamReader(    
  18.                    httpConn.getInputStream(),"UTF-8"));    
  19.            String line;    
  20.            while ((line = in.readLine()) != null) {    
  21.                result .append(line);    
  22.            }    
  23.            //System.out.println(result);  
  24.            in.close();  
  25.            //get token  
  26.            return result.toString().split("\"")[15];  
  27.        } catch (Exception e) {    
  28.            e.printStackTrace();            
  29.        }  
  30.        return null;  
  31.    }}  





SCGISModel.java:切片参数定义文件,包括切片的空间参考等基础信息



[java] view plaincopy

  1. package com.esri.arcgis.android.samples;  
  2.  
  3. import java.io.BufferedInputStream;  
  4. import java.io.ByteArrayOutputStream;  
  5. import java.io.File;  
  6. import java.net.HttpURLConnection;  
  7. import java.net.URL;  
  8. import com.esri.core.geometry.Envelope;  
  9. import com.esri.core.geometry.SpatialReference;  
  10. import com.esri.core.internal.d.k;  
  11.  
  12. import com.esri.core.map.TiledLayerModel;  
  13.  
  14. public class SCGISModel extends TiledLayerModel {  
  15.    private static final long serialVersionUID = 7726567118839553087L;  
  16.      
  17.    private String location;  
  18.    private String token;  
  19.    public SCGISModel(String location, SpatialReference sr, Envelope full,  
  20.        k tileInfo) {  
  21.    super(sr, full, tileInfo);  
  22.    this.location = location;  
  23.    this.token=new GetToken().sendPost("http://www.scgis.net.cn/imap/iMapServer/Token/getToken?username=test20110703&password=test20110703&IpAddress=&TimeSpan=100M&st=1302073818076");  
  24.    }  
  25.          
  26.    @Override  
  27.    public byte[] getTile(int level, int row, int col) throws Exception {  
  28.    byte[] result = null;  
  29.        try {  
  30.            int levelCustom = level + 1;  
  31.            String bundlesDir = location  
  32.                    + levelCustom  
  33.                    + File.separator  
  34.                    + row  
  35.                    + File.separator  
  36.                    + col  
  37.                    + "?token="+this.token;  
  38.            ;  
  39.  
  40.            ByteArrayOutputStream bos = new ByteArrayOutputStream();  
  41.  
  42.            URL sjwurl = new URL(bundlesDir);  
  43.            HttpURLConnection httpUrl = null;  
  44.            BufferedInputStream bis = null;  
  45.            byte[] buf = new byte[1024];  
  46.  
  47.            httpUrl = (HttpURLConnection) sjwurl.openConnection();  
  48.            httpUrl.connect();  
  49.            bis = new BufferedInputStream(httpUrl.getInputStream());  
  50.              
  51.            while (true) {  
  52.                int bytes_read = bis.read(buf);  
  53.                if (bytes_read > 0) {  
  54.                    bos.write(buf, 0, bytes_read);  
  55.                } else {  
  56.                    break;  
  57.                }  
  58.            }  
  59.            ;  
  60.            bis.close();  
  61.            httpUrl.disconnect();  
  62.  
  63.            result = bos.toByteArray();  
  64.  
  65.        } catch (Exception ex) {  
  66.            ex.printStackTrace();  
  67.        }  
  68.  
  69.    return result;  
  70.    }  
  71.  
  72. }  




SCGISMapServices.java:继承tiledLayer,自定义切片类。



[java] view plaincopy

  1. package com.esri.arcgis.android.samples;  
  2. import java.util.ArrayList;  
  3. import android.content.Context;  
  4. import android.util.AttributeSet;  
  5.  
  6. import com.esri.android.map.TiledLayer;  
  7. import com.esri.core.geometry.Envelope;  
  8. import com.esri.core.geometry.Point;  
  9. import com.esri.core.geometry.SpatialReference;  
  10. import com.esri.core.internal.d.c;  
  11. import com.esri.core.internal.d.k;  
  12. import com.esri.core.map.TiledLayerModel;  
  13.  
  14. public class SCGISMapServices extends TiledLayer {  
  15.    private String location = "http://www.scgis.net.cn/iMap/iMapServer/NewRest/services/SCTileMap/tile/";  
  16.  
  17.    private SpatialReference spatialReference = SpatialReference.create(4326);  
  18.    private Envelope fullExtent = new Envelope(95.918, 24.898, 110.14, 35.209);  
  19.    private k tileInfo;  
  20.  
  21.    public SCGISMapServices(Context context, AttributeSet attrs) {  
  22.        super(context, attrs);  
  23.        try {  
  24.            init();  
  25.        } catch (Exception ex) {  
  26.            ex.printStackTrace();  
  27.        }  
  28.    }  
  29.  
  30.    @Override  
  31.    protected TiledLayerModel initModel() throws Exception {  
  32.        return new SCGISModel(location, spatialReference, fullExtent, tileInfo);  
  33.    }  
  34.  
  35.    private void init() {  
  36.        try {  
  37.            tileInfo = new k();          
  38.            tileInfo.f = new Point(-180, 90);  
  39.  
  40.              
  41.            tileInfo.a = 256;            
  42.            tileInfo.b = 256;  
  43.            tileInfo.h = new ArrayList<c>();  
  44.              
  45.            double resolution = 0.010998662747496;  
  46.            double scale=4622333.68;  
  47.            for (int j = 0, jcount = 11; j < jcount; j++) {                
  48.                int level = j;  
  49.                tileInfo.h.add(new AgsLOD(level, scale, resolution));                
  50.                resolution/=2;  
  51.                scale/=2;  
  52.            }  
  53.        } catch (Exception e) {  
  54.            e.printStackTrace();  
  55.        }  
  56.    }  
  57.  
  58. }  
4)效果图如下:





如果需代码学习的同学,在本系列专题之五后面留下邮箱,可将此系列专题的所有代码提供出来供大学学习!
http://blog.csdn.net/esrichinacd/article/details/7782424

举报 回复(0) 喜欢(0)     评分
游客

返回顶部