guotiantian_5736

for android,how to creating a custom tiled layer type

Discussion created by guotiantian_5736 on Oct 22, 2012
This is my realization, is wrong

public class CustomTiledMapServiceLayer extends TiledServiceLayer{

               private TileInfo _titlinfo;
private static final double c[] = {
  4891.96981024998D, 2445.98490512499D, 1222.99245256249D, 611.49622628138D, 305.748113140558D, 152.874056570411D, 76.4370282850732D, 38.2185141425366D, 19.1092570712683D, 9.55462853563415D,
  4.77731426794937D
};
private static final double d[] = {
  18489297.737236D, 9244648.868618D, 4622324.434309D, 2311162.217155D, 1155581.108577D, 577790.554289D, 288895.277144D, 144447.638572D, 72223.819286D, 36111.909643D,
  18055.954822D
};


              @Override

protected byte[] getTile(int level, int col, int row) throws Exception {
  String url  = "http://mt"+(col%4)+".google.cn/vt/lyrs=t@128,r@174000000&hl=zh-CN&gl=cn&src=app&x="+col+"&y="+row+"&z="+level+"&s=";
  return url.getBytes();
}
              @Override
              protected void initLayer() {
  try {
   setTileInfo(new com.esri.android.map.TiledServiceLayer.TileInfo(new Point(-20037508.342787D, 20037508.342787D), d, c, d.length, 96, 256, 256));
   Envelope envelope1 = (Envelope)GeometryEngine.project(getInitialExtent(), SpatialReference.create(102113), getDefaultSpatialReference());
   setInitialExtent(envelope1);
   Envelope envelope = (Envelope)GeometryEngine.project(getInitialExtent(), SpatialReference.create(102113), getDefaultSpatialReference());
   setInitialExtent(envelope);
   super.initLayer();
   return;
  }
  catch (Exception exception) {
  }
}
}





Activity:
                  CustomTiledMapServiceLayer tileLayer = new CustomTiledMapServiceLayer("http://192.168.30.48:8080                                                                /MapProxy/mapLayers/Google/PHYSICAL/");
                  map.addLayer(tileLayer);





error message:
10-23 07:49:39.898: E/AndroidRuntime(10268): FATAL EXCEPTION: main
10-23 07:49:39.898: E/AndroidRuntime(10268): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.esri.arcgis.android.samples.helloworld/com.esri.arcgis.android.samples.helloworld.HelloWorld}: android.view.InflateException: Binary XML file line #9: Error inflating class com.esri.android.map.MapView
10-23 07:49:39.898: E/AndroidRuntime(10268):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
10-23 07:49:39.898: E/AndroidRuntime(10268):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
10-23 07:49:39.898: E/AndroidRuntime(10268):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
10-23 07:49:39.898: E/AndroidRuntime(10268):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
10-23 07:49:39.898: E/AndroidRuntime(10268):  at android.os.Handler.dispatchMessage(Handler.java:99)
10-23 07:49:39.898: E/AndroidRuntime(10268):  at android.os.Looper.loop(Looper.java:123)
10-23 07:49:39.898: E/AndroidRuntime(10268):  at android.app.ActivityThread.main(ActivityThread.java:4627)
10-23 07:49:39.898: E/AndroidRuntime(10268):  at java.lang.reflect.Method.invokeNative(Native Method)
10-23 07:49:39.898: E/AndroidRuntime(10268):  at java.lang.reflect.Method.invoke(Method.java:521)
10-23 07:49:39.898: E/AndroidRuntime(10268):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:876)
10-23 07:49:39.898: E/AndroidRuntime(10268):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:634)
10-23 07:49:39.898: E/AndroidRuntime(10268):  at dalvik.system.NativeStart.main(Native Method)
10-23 07:49:39.898: E/AndroidRuntime(10268): Caused by: android.view.InflateException: Binary XML file line #9: Error inflating class com.esri.android.map.MapView
10-23 07:49:39.898: E/AndroidRuntime(10268):  at android.view.LayoutInflater.createView(LayoutInflater.java:513)
10-23 07:49:39.898: E/AndroidRuntime(10268):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:565)
10-23 07:49:39.898: E/AndroidRuntime(10268):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
10-23 07:49:39.898: E/AndroidRuntime(10268):  at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
10-23 07:49:39.898: E/AndroidRuntime(10268):  at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
10-23 07:49:39.898: E/AndroidRuntime(10268):  at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
10-23 07:49:39.898: E/AndroidRuntime(10268):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
10-23 07:49:39.898: E/AndroidRuntime(10268):  at android.app.Activity.setContentView(Activity.java:1650)
10-23 07:49:39.898: E/AndroidRuntime(10268):  at com.esri.arcgis.android.samples.helloworld.HelloWorld.onCreate(HelloWorld.java:28)
10-23 07:49:39.898: E/AndroidRuntime(10268):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
10-23 07:49:39.898: E/AndroidRuntime(10268):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
10-23 07:49:39.898: E/AndroidRuntime(10268):  ... 11 more
10-23 07:49:39.898: E/AndroidRuntime(10268): Caused by: java.lang.reflect.InvocationTargetException
10-23 07:49:39.898: E/AndroidRuntime(10268):  at com.esri.android.map.MapView.<init>(Unknown Source)
10-23 07:49:39.898: E/AndroidRuntime(10268):  at java.lang.reflect.Constructor.constructNative(Native Method)
10-23 07:49:39.898: E/AndroidRuntime(10268):  at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
10-23 07:49:39.898: E/AndroidRuntime(10268):  at android.view.LayoutInflater.createView(LayoutInflater.java:500)
10-23 07:49:39.898: E/AndroidRuntime(10268):  ... 21 more
10-23 07:49:39.898: E/AndroidRuntime(10268): Caused by: java.lang.ArrayIndexOutOfBoundsException
10-23 07:49:39.898: E/AndroidRuntime(10268):  at com.esri.android.map.MapView.a(Unknown Source)
10-23 07:49:39.898: E/AndroidRuntime(10268):  ... 25 more

Outcomes