private void openMap1() { String url = "http://t0.tianditu.gov.cn/vec_c/wmts?tk=15fcda84316f12183782bd4511f18d79"; workspace = new Workspace(); DatasourceConnectionInfo info = new DatasourceConnectionInfo(); info.setServer(url); info.setEngineType(EngineType.OGC); info.setDriver("WMTS"); info.setAlias("tianditu_wmts"); Datasource datasource = workspace.getDatasources().open(info); if (datasource == null) { Toast.makeText(this, "数据源打开失败", Toast.LENGTH_SHORT).show(); return; } }
按照博客里边的把代码换了一下加载不出来天地图二维图
您好,这边看了您的代码,没有看到添加图层呢应该再加上
mapcontrol.getMap().getLayers().add(datasource.getDatasets().get(0),true);
您那边加上看看有没有呢
这是我添加天地图的代码
DatasourceConnectionInfo dinfo = new DatasourceConnectionInfo(); dinfo.setAlias("TianDiTu12"); dinfo.setDriver("WMTS"); String url = "http://t0.tianditu.gov.cn/img_c/wmts?&DPI=96&tk=410199522650980db3dfb843a809a2a4"; dinfo.setEngineType(EngineType.OGC); dinfo.setServer(url); Datasource d1 = woWorkspace.getDatasources().open(dinfo); mapControl.getMap().getLayers().add(d1.getDatasets().get(0),true); mapControl.getMap().refresh();
链接:https://pan.baidu.com/s/11S8TZErUHbHF4nzcEvnhBA 提取码:8754
这是二维点动画的demo其中点为固定点,通过一线程实现,您可以得到三维飞机的图层设置为动态点的坐标
我把您这个代码加到我那里边直接闪退报错了 不加没有事 加了就是闪退报错的
报错 那行是:
Datasource d1 = workspace.getDatasources().open(dinfo);
错误如下:
E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.map, PID: 29332 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.map/com.example.map.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'com.supermap.data.Datasources com.supermap.data.Workspace.getDatasources()' on a null object reference at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4060) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4247) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:91) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:149) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:103) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2613) at android.os.Handler.dispatchMessage(Handler.java:110) at android.os.Looper.loop(Looper.java:219) at android.app.ActivityThread.main(ActivityThread.java:8668) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1109) Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'com.supermap.data.Datasources com.supermap.data.Workspace.getDatasources()' on a null object reference at com.example.map.MainActivity.onCreate(MainActivity.java:202) at android.app.Activity.performCreate(Activity.java:8214) at android.app.Activity.performCreate(Activity.java:8202) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1320) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4033) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4247) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:91) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:149) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:103) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2613) at android.os.Handler.dispatchMessage(Handler.java:110) at android.os.Looper.loop(Looper.java:219) at android.app.ActivityThread.main(ActivityThread.java:8668) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1109)