博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

重写TiledServiceLayer实现Arcgis访问Mapabc地图服务 (转载)

Posted on 2014-02-07 15:33  张冰  阅读(879)  评论(0编辑  收藏  举报

package com.baixin.main;
/**
 *
 * @ClassName:   MapAbcToArcGISTLayer
 * @Description:    ArcGIS访问MapAbc地图服务
 * @author:        Zrd
 * @version:       v1.0 
 * @Date:          2012-8-11 上午10:18:17
 */
import java.util.HashMap;
import com.esri.android.map.TiledServiceLayer;
import com.esri.core.geometry.Envelope;
import com.esri.core.geometry.Point;
import com.esri.core.geometry.SpatialReference;
import com.esri.core.internal.b.a.a;


public class MapAbcToArcGISTLayer extends TiledServiceLayer {
 private int WKID = 2436;
 private String layername = null;
    private String layerurl = null;
 private static final double[] c = { 896.0859375, 548.04296875,
   224.02148437, 112.0107421875, 56.00537109375, 28.002685546875,
   14.0013427734375, 7.00067138671875, 3.50033569335937,
   1.75016784667968, 0.875083923339843, 0.4375419616699215,
   0.2187709808349608 };
 private static final double[] d = { 3386781.496062992D, 1693390.748031496D,
   846695.374015748D, 423347.687007874D, 211673.843503937D,
   105836.92175196858D, 52918.46087598425D, 26459.23043799213D,
   13229.61521899604D, 6614.807609498003D, 3307.403804749013D,
   1653.701902374507D, 826.8509511872533D };
 private static final double[] res = { 0.0011159643937610616,
   0.0032319287875221232, 0.0044638575750442465, 0.008927715150088493,
   0.017855430300176986, 0.03571086060035397, 0.07142172120070794,
   0.1428434424014159, 0.2856868848028318, 0.5713737696056635,
   1.143547539211327, 2.287295078422654, 4.574490156845308 };
 public static final int initWithDpi = 96;
 public MapAbcToArcGISTLayer(String layerurl,String layername) {
  super(layerurl);
  this.layerurl = layerurl;
  this.layername = layername;
  initLayer();
 }
 protected void initLayer() {
  if(getID()==0){
   this.nativeHandle = create();
  }
  try {
   SpatialReference localSpatialReference = SpatialReference.create(WKID);
   setDefaultSpatialReference(localSpatialReference);
   Envelope localEnvelope = new Envelope(371987.18333999999D,
     252920.58593D, 624459.12035999994D, 423400.07714000001D);
   setFullExtent(localEnvelope);
   Point localPoint = new Point(0.0D, 458793.07714);
   double[] arrayOfDoublescale = d;
   double[] arrayOfDoubleres = c;
   int k = d.length;
   TiledServiceLayer.TileInfo localTileInfo = new TiledServiceLayer.TileInfo(
     localPoint, arrayOfDoublescale, arrayOfDoubleres, k, 96,
     256, 256);
   setTileInfo(localTileInfo);
   super.initLayer();
   return;
  } catch (Exception localException) {
   localException.printStackTrace();
  }
 }


 @Override
 protected byte[] getTile(int level, int col, int row) throws Exception {
  // TODO Auto-generated method stub
  int nrow  = (int) (Math.floor((458400.07714) * res[level] / 256) - row);
  String strUrl = layerurl + "x=" + col + "&y=" + nrow + "&z=" + level
    + "&type=ic&layer="+layername+"";
  HashMap<String, String> localHashMap = new HashMap<String, String>();
  byte[] bytes = a.a(strUrl, localHashMap);
  return bytes;
 }
}