创建一个imobile【supermap-java】项目,并添加天地图/百度地图
创建Android项目,完成项目初始化设置
-
创建一个empty activity的Android项目 -
设置语言为java,并设置支持的minimum API为 18 -
设置gradle 版本
gradle 版本小于等于5.5
- 注释掉setting.gradle文件里的求部分,保留如下内容:
pluginManagement {
repositories {
gradlePluginPortal()
google()
mavenCentral()
}
}
//dependencyResolutionManagement {
// repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
// repositories {
// google()
// mavenCentral()
// }
//}
rootProject.name = "SuperMaptTest2"
include ':app'
- 设置build.gradle(Module:.app)
修改后内容如下:
plugins {
id 'com.android.application'
}
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
defaultConfig {
applicationId "com.example.supermapttest2"
minSdkVersion 18
//noinspection ExpiredTargetSdkVersion
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
ndk {
abiFilters 'armeabi-v7a'
}
splits {
abi {
enable true
reset()
include 'x86', 'armeabi-v7a','x86_64'
universalApk true
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main {
jniLibs.srcDirs = ['libs']
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
- 设置build.gradle(Project:)
修改后内容如下
// Top-level build file where you can add configuration options common to all sub-projects/modules.
//plugins {
// id 'com.android.application' version '3.4.3' apply false
// id 'com.android.library' version '3.4.3' apply false
//}
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
配置adb工具(上传文件,新建文件路径)
在环境中配置SDK的tools和platform-tools
D:\appdata\Local\Andriod\Sdk\tools
D:\appdata\Local\Andriod\Sdk\platform-tools
上传文件:adb push /被上传文件路径/ /文件上传在Android中的路径/ 查看当前路径下得文件:adb shell ls ./ 创建SuperMap文件夹:adb shell mkdir /SuperMap
配置jar包和so依赖
- 将mapping包和data包复制到libs下,右键选择“add as library”。
- 将.so包复制到
libs/armeabi-v7a/ 文件夹下。
编写supermap程序
AndroidManifest.xml和layout中的activity_main.xml(此处可见supermap的imobile的帮助文档部分)
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.supermaptest0225">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<supports-screens
android:anyDensity="true"
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.SuperMapTest0225"
android:configChanges="keyboardHidden|orientation|screenSize">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<com.supermap.mapping.MapView
android:id = "@+id/Map_view"
android:layout_width="match_parent"
android:layout_height = "match_parent">
</com.supermap.mapping.MapView>
</androidx.constraintlayout.widget.ConstraintLayout>
读取许可文件信息,加载(天地图)百度地图。
super.onCreate(savedInstanceState);
MapControl mapControl = null;
String rootPath = android.os.Environment.getExternalStorageDirectory().getAbsolutePath();
Environment.setLicensePath(rootPath + "/SuperMap/license/");
Log.d("TAG", "onCreate: \n"+rootPath + "/SuperMap/license/");
Environment.initialization(this);
setContentView(R.layout.activity_main);
setContentView(R.layout.activity_main);
MapView m_mapView = findViewById(R.id.Map_view);
Workspace m_workspace = new Workspace();
WorkspaceConnectionInfo workinfo = new WorkspaceConnectionInfo();
workinfo.setServer(rootPath + "/SampleData/GeometryInfo/World.smwu");
workinfo.setType(WorkspaceType.SMWU);
m_workspace.open(workinfo);
DatasourceConnectionInfo baiduMapDatasourceInfo=new DatasourceConnectionInfo();
baiduMapDatasourceInfo.setAlias("BaiDu1");
baiduMapDatasourceInfo.setEngineType(EngineType.BaiDu);
String url = "https://map.baidu.com";
baiduMapDatasourceInfo.setServer(url);
Datasource baiduDatasource=m_workspace.getDatasources().open(baiduMapDatasourceInfo);
mapControl=m_mapView.getMapControl();
mapControl.getMap().setWorkspace(m_workspace);
mapControl.getMap().getLayers().add(baiduDatasource.getDatasets().get(0),true);
mapControl.getMap().refresh();
urces().open(baiduMapDatasourceInfo);
mapControl=m_mapView.getMapControl();
mapControl.getMap().setWorkspace(m_workspace);
mapControl.getMap().getLayers().add(baiduDatasource.getDatasets().get(0),true);
mapControl.getMap().refresh();
|