调整mapapi

This commit is contained in:
squallzhjch 2023-03-24 13:56:13 +08:00
parent 6a249a254a
commit 5e8b75005f
43 changed files with 1873 additions and 1631 deletions

View File

@ -24,8 +24,8 @@ android {
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'

View File

@ -1,18 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
xmlns:tools="http://schemas.android.com/tools"
package="com.navinfo.omqs">
<!-- 这个权限用于进行网络定位-->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<!-- 这个权限用于访问GPS定位-->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- 用于访问wifi网络信息wifi信息会用于进行网络定位-->
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<!-- 获取运营商信息,用于支持提供运营商信息相关的接口-->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- 这个权限用于获取wifi的获取权限wifi信息会用来进行网络定位-->
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<!-- 写入扩展存储,向扩展卡写入数据,用于写入离线定位数据-->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- 访问网络,网络定位需要上网 -->
<uses-permission android:name="android.permission.INTERNET" />
<!-- 允许访问振动设备 -->
<uses-permission android:name="android.permission.VIBRATE" />
<!-- 允许使用PowerManager的 WakeLocks保持进程在休眠时从屏幕消失 -->
<uses-permission android:name="android.permission.WAKE_LOCK" />
<!-- android 9.0上使用前台服务,需要添加权限 -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<!-- 用于读取手机当前的状态 -->
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<!-- 读取缓存数据 -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:requestLegacyExternalStorage="true"
android:supportsRtl="true"
android:theme="@style/Theme.OMQualityInspection"
tools:targetApi="31">
<activity
android:name=".ui.LoginActivity"
android:name=".ui.activity.LoginActivity"
android:exported="true"
android:label="@string/app_name"
android:theme="@style/Theme.OMQualityInspection">
@ -22,6 +47,10 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ui.activity.MainActivity"
android:exported="true"
android:theme="@style/Theme.OMQualityInspection"></activity>
</application>
</manifest>

View File

@ -1,13 +0,0 @@
package com.navinfo.omqs.ui
import android.content.pm.ActivityInfo
import android.os.Bundle
import android.os.PersistableBundle
import androidx.appcompat.app.AppCompatActivity
open class BaseActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?, persistentState: PersistableBundle?) {
super.onCreate(savedInstanceState, persistentState)
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE//横屏
}
}

View File

@ -1,33 +0,0 @@
package com.navinfo.omqs.ui
import android.os.Bundle
import android.os.PersistableBundle
import androidx.activity.viewModels
import androidx.databinding.DataBindingUtil
import com.navinfo.omqs.R
import com.navinfo.omqs.databinding.ActivityLoginBinding
class LoginActivity : PermissionsActivity() {
private lateinit var binding: ActivityLoginBinding
private val viewModel by viewModels<LoginActivityViewModel>()
override fun onCreate(savedInstanceState: Bundle?, persistentState: PersistableBundle?) {
super.onCreate(savedInstanceState, persistentState)
binding = DataBindingUtil.inflate(layoutInflater, R.layout.activity_login, null, false)
binding.lifecycleOwner = this
setContentView(binding.root)
}
override fun onPermissionsGranted() {
initView()
}
private fun initView() {
}
override fun onPermissionsDenied() {
}
}

View File

@ -1,7 +0,0 @@
package com.navinfo.omqs.ui
import androidx.lifecycle.ViewModel
class LoginActivityViewModel : ViewModel() {
}

View File

@ -1,62 +0,0 @@
package com.navinfo.omqs.ui
import android.os.Bundle
import com.google.android.material.snackbar.Snackbar
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.WindowCompat
import androidx.navigation.findNavController
import androidx.navigation.ui.AppBarConfiguration
import androidx.navigation.ui.navigateUp
import androidx.navigation.ui.setupActionBarWithNavController
import android.view.Menu
import android.view.MenuItem
import com.navinfo.omqs.R
import com.navinfo.omqs.databinding.ActivityMainBinding
class MainActivity : AppCompatActivity() {
private lateinit var appBarConfiguration: AppBarConfiguration
private lateinit var binding: ActivityMainBinding
override fun onCreate(savedInstanceState: Bundle?) {
WindowCompat.setDecorFitsSystemWindows(window, false)
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
setSupportActionBar(binding.toolbar)
val navController = findNavController(R.id.nav_host_fragment_content_main)
appBarConfiguration = AppBarConfiguration(navController.graph)
setupActionBarWithNavController(navController, appBarConfiguration)
binding.fab.setOnClickListener { view ->
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAnchorView(R.id.fab)
.setAction("Action", null).show()
}
}
override fun onCreateOptionsMenu(menu: Menu): Boolean {
// Inflate the menu; this adds items to the action bar if it is present.
menuInflater.inflate(R.menu.menu_main, menu)
return true
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
return when (item.itemId) {
R.id.action_settings -> true
else -> super.onOptionsItemSelected(item)
}
}
override fun onSupportNavigateUp(): Boolean {
val navController = findNavController(R.id.nav_host_fragment_content_main)
return navController.navigateUp(appBarConfiguration)
|| super.onSupportNavigateUp()
}
}

View File

@ -0,0 +1,16 @@
package com.navinfo.omqs.ui.activity
import android.content.pm.ActivityInfo
import android.os.Bundle
import android.os.PersistableBundle
import androidx.appcompat.app.AppCompatActivity
/**
* 基类
*/
open class BaseActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE//横屏
super.onCreate(savedInstanceState)
}
}

View File

@ -0,0 +1,40 @@
package com.navinfo.omqs.ui.activity
import android.content.Intent
import android.os.Bundle
import androidx.activity.viewModels
import androidx.databinding.DataBindingUtil
import com.navinfo.omqs.R
import com.navinfo.omqs.databinding.ActivityLoginBinding
/**
* 登陆页面
*/
class LoginActivity : PermissionsActivity() {
private lateinit var binding: ActivityLoginBinding
private val viewModel by viewModels<LoginViewModel>()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = DataBindingUtil.setContentView(this, R.layout.activity_login)
binding.loginUserModel = viewModel
binding.lifecycleOwner = this
binding.activity = this
}
override fun onPermissionsGranted() {
}
override fun onPermissionsDenied() {
}
/**
* 处理登录按钮
*/
fun onClickLoginButton() {
val intent = Intent(this@LoginActivity, MainActivity::class.java)
startActivity(intent)
finish()
}
}

View File

@ -0,0 +1,23 @@
package com.navinfo.omqs.ui.activity
import android.view.View
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.navinfo.omqs.model.LoginUser
class LoginViewModel : ViewModel() {
val loginUser: MutableLiveData<LoginUser> = MutableLiveData()
init {
loginUser.value = LoginUser(username = "admin", password = "123456")
}
/**
* 处理注册按钮
*/
fun onClick(view: View) {
loginUser.value!!.username = "admin2"
loginUser.postValue(loginUser.value)
}
}

View File

@ -0,0 +1,32 @@
package com.navinfo.omqs.ui.activity
import android.os.Bundle
import androidx.activity.viewModels
import androidx.core.view.WindowCompat
import androidx.databinding.DataBindingUtil
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleEventObserver
import androidx.lifecycle.LifecycleObserver
import androidx.lifecycle.LifecycleOwner
import com.navinfo.omqs.R
import com.navinfo.omqs.databinding.ActivityMainBinding
/**
* 地图主页面
*/
class MainActivity : BaseActivity() {
private lateinit var binding: ActivityMainBinding
private val viewModel by viewModels<MainViewModel>()
override fun onCreate(savedInstanceState: Bundle?) {
WindowCompat.setDecorFitsSystemWindows(window, false)
super.onCreate(savedInstanceState)
binding = DataBindingUtil.setContentView(this, R.layout.activity_main)
binding.lifecycleOwner = this
viewModel.initMap(this, binding.mainActivityMap)
lifecycle.addObserver(viewModel)
// val navController = findNavController(R.id.nav_host_fragment_content_main)
}
}

View File

@ -0,0 +1,36 @@
package com.navinfo.omqs.ui.activity
import android.content.Context
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.ViewModel
import com.navinfo.collect.library.map.NIMapController
import com.navinfo.collect.library.map.NIMapView
class MainViewModel : ViewModel(), DefaultLifecycleObserver {
private lateinit var mapController: NIMapController
fun initMap(context: Context, mapView: NIMapView) {
mapController = NIMapController(context = context, mapView = mapView)
}
override fun onStart(owner: LifecycleOwner) {
super.onStart(owner)
mapController.locationLayerHandler.startLocation()
}
override fun onPause(owner: LifecycleOwner) {
mapController.mMapView.onPause()
}
override fun onDestroy(owner: LifecycleOwner) {
mapController.mMapView.onDestroy()
mapController.locationLayerHandler.stopLocation()
}
override fun onResume(owner: LifecycleOwner) {
mapController.mMapView.onResume()
}
}

View File

@ -1,9 +1,8 @@
package com.navinfo.omqs.ui
package com.navinfo.omqs.ui.activity
import android.os.Build
import android.os.Bundle
import android.os.PersistableBundle
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.hjq.permissions.OnPermissionCallback
import com.hjq.permissions.Permission
import com.hjq.permissions.XXPermissions
@ -11,14 +10,30 @@ import com.hjq.permissions.XXPermissions
/**
* 权限申请Activity
*/
abstract class PermissionsActivity : BaseActivity() {
override fun onCreate(savedInstanceState: Bundle?, persistentState: PersistableBundle?) {
super.onCreate(savedInstanceState, persistentState)
open class PermissionsActivity : BaseActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val permissionList = mutableListOf<String>()
if (applicationInfo.targetSdkVersion >= Build.VERSION_CODES.TIRAMISU) {
//文件读写
permissionList.add(Permission.READ_MEDIA_IMAGES)
permissionList.add(Permission.READ_MEDIA_AUDIO)
permissionList.add(Permission.READ_MEDIA_VIDEO)
} else {
//文件读写
permissionList.add(Permission.WRITE_EXTERNAL_STORAGE)
permissionList.add(Permission.READ_EXTERNAL_STORAGE)
permissionList.add(Permission.READ_MEDIA_VIDEO)
}
//定位权限
permissionList.add(Permission.ACCESS_FINE_LOCATION)
permissionList.add(Permission.ACCESS_COARSE_LOCATION)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
permissionList.add(Permission.ACCESS_BACKGROUND_LOCATION)
}
XXPermissions.with(this)
// 申请单个权限
.permission(Permission.WRITE_EXTERNAL_STORAGE)
.permission(Permission.READ_EXTERNAL_STORAGE)
.permission(permissionList)
// 设置权限请求拦截器(局部设置)
//.interceptor(new PermissionInterceptor())
// 设置不触发错误检测机制(局部设置)
@ -35,6 +50,8 @@ abstract class PermissionsActivity : BaseActivity() {
.show()
onPermissionsGranted()
return
} else {
onPermissionsDenied()
}
// 在SD卡创建项目目录
}
@ -51,11 +68,23 @@ abstract class PermissionsActivity : BaseActivity() {
XXPermissions.startPermissionActivity(this@PermissionsActivity, permissions)
onPermissionsDenied()
} else {
onPermissionsDenied()
}
}
})
}
abstract fun onPermissionsGranted()
abstract fun onPermissionsDenied()
/**
* 权限全部同意
*/
open fun onPermissionsGranted() {
}
/**
* 权限
*/
open fun onPermissionsDenied() {
}
}

View File

@ -1,4 +1,4 @@
package com.navinfo.omqs
package com.navinfo.omqs.ui.fragment
import android.os.Bundle
import androidx.fragment.app.Fragment
@ -6,6 +6,7 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.navigation.fragment.findNavController
import com.navinfo.omqs.R
import com.navinfo.omqs.databinding.FragmentFirstBinding
/**

View File

@ -1,4 +1,4 @@
package com.navinfo.omqs
package com.navinfo.omqs.ui.fragment
import android.os.Bundle
import androidx.fragment.app.Fragment
@ -6,6 +6,7 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.navigation.fragment.findNavController
import com.navinfo.omqs.R
import com.navinfo.omqs.databinding.FragmentSecondBinding
/**
@ -22,7 +23,7 @@ class SecondFragment : Fragment() {
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
): View {
_binding = FragmentSecondBinding.inflate(inflater, container, false)
return binding.root

View File

@ -4,27 +4,33 @@
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable
name="loginUser"
type="com.navinfo.omqs.model.LoginUser" />
name="activity"
type="com.navinfo.omqs.ui.activity.LoginActivity" />
<variable
name="loginUserModel"
type="com.navinfo.omqs.ui.activity.LoginViewModel" />
</data>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.navinfo.volvo.ui.fragments.login.LoginFragment">
tools:context=".ui.activity.LoginActivity">
<ImageView
android:id="@+id/login_fragment_logo"
android:layout_width="100dp"
android:layout_height="100dp"
android:contentDescription="@string/imagedescription"
android:scaleType="fitXY"
android:src="@mipmap/ic_launcher"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.2"
app:layout_constraintVertical_bias="0.1"
app:roundPercent="0.2" />
<com.google.android.material.textfield.TextInputLayout
@ -43,8 +49,8 @@
android:id="@+id/login_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@{loginUser.username}"
android:hint="请输入用户名" />
android:hint="@string/input_user_name"
android:text="@{loginUserModel.loginUser.username}" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
@ -58,32 +64,34 @@
android:id="@+id/login_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/input_password"
android:inputType="textPassword"
android:text="@{loginUser.password}"
android:hint="请输入密码" />
android:text="@{loginUserModel.loginUser.password}" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
android:id="@+id/login_fragment_register_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="@{(view)->loginUserModel.onClick(view)}"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="注册"
android:text="@string/logon"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_chainStyle="spread"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@id/login_fragment_login_button"
app:layout_constraintRight_toLeftOf="@id/login_activity_login_button"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.7" />
app:layout_constraintVertical_bias="0.8" />
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
android:id="@+id/login_fragment_login_button"
android:id="@+id/login_activity_login_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="@{()->activity.onClickLoginButton()}"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="登录"
android:text="@string/login"
app:layout_constraintBaseline_toBaselineOf="@id/login_fragment_register_button"
app:layout_constraintLeft_toRightOf="@id/login_fragment_register_button"
app:layout_constraintRight_toRightOf="parent" />

View File

@ -1,34 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
<layout 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"
android:fitsSystemWindows="true"
tools:context=".ui.MainActivity">
xmlns:tools="http://schemas.android.com/tools">
<com.google.android.material.appbar.AppBarLayout
<data>
</data>
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true">
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".ui.activity.MainActivity">
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"
<com.navinfo.collect.library.map.NIMapView
android:id="@+id/main_activity_map"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize" />
android:layout_height="match_parent" />
</com.google.android.material.appbar.AppBarLayout>
<include layout="@layout/content_main" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_marginEnd="@dimen/fab_margin"
android:layout_marginBottom="16dp"
app:srcCompat="@android:drawable/ic_dialog_email" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</layout>

View File

@ -4,7 +4,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".FirstFragment">
tools:context=".ui.fragment.FirstFragment">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"

View File

@ -4,7 +4,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".SecondFragment">
tools:context=".ui.fragment.SecondFragment">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"

View File

@ -1,7 +1,7 @@
<menu 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"
tools:context="com.navinfo.omqs.ui.MainActivity">
tools:context="com.navinfo.omqs.ui.activity.MainActivity">
<item
android:id="@+id/action_settings"
android:orderInCategory="100"

View File

@ -7,7 +7,7 @@
<fragment
android:id="@+id/FirstFragment"
android:name="com.navinfo.omqs.FirstFragment"
android:name="com.navinfo.omqs.ui.fragment.FirstFragment"
android:label="@string/first_fragment_label"
tools:layout="@layout/fragment_first">
@ -17,7 +17,7 @@
</fragment>
<fragment
android:id="@+id/SecondFragment"
android:name="com.navinfo.omqs.SecondFragment"
android:name="com.navinfo.omqs.ui.fragment.SecondFragment"
android:label="@string/second_fragment_label"
tools:layout="@layout/fragment_second">

View File

@ -43,4 +43,9 @@
libero vel nunc consequat, quis tincidunt nisl eleifend. Cras bibendum enim a justo luctus
vestibulum. Fusce dictum libero quis erat maximus, vitae volutpat diam dignissim.
</string>
<string name="input_user_name">请输入用户名</string>
<string name="input_password">请输入密码</string>
<string name="login">登录</string>
<string name="logon">注册</string>
<string name="imagedescription">imageDescription</string>
</resources>

View File

@ -56,7 +56,7 @@ android {
dependencies {
api fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
api files('libs/BaiduLBS_AndroidSDK_Lib.aar')
implementation "androidx.appcompat:appcompat:$appcompatVersion"
implementation "com.google.android.material:material:$materialVersion"
testImplementation 'junit:junit:4.13.2'

Binary file not shown.

View File

@ -8,13 +8,14 @@
<data android:mimeType="*/*"/>
</intent>
</queries>
<!-- <application-->
<!-- android:allowBackup="true"-->
<!-- >-->
<!-- <activity-->
<!-- android:name="com.navinfo.ocr.CameraActivity"-->
<!-- android:exported="true"/>-->
<!-- </application>-->
<!-- AK鉴权 -->
<meta-data
android:name="com.baidu.lbsapi.API_KEY"
android:value="IxQi4mZGTlfv6Z9M2GRdqn4KKRbOATUU" />
<application
android:allowBackup="true"
android:networkSecurityConfig="@xml/network_security_config"
>
</application>
</manifest>

View File

@ -6,7 +6,6 @@ import android.util.Log;
import com.google.protobuf.GeneratedMessageV3;
import com.navinfo.collect.library.data.entity.GeometryFeatureEntity;
import com.navinfo.collect.library.data.entity.LayerEntity;
import com.navinfo.collect.library.map.NILayerManager;
import com.navinfo.collect.library.utils.GeometryTools;
import com.navinfo.onemap.det.sdkpbf.proto.crowdsource.Hadlanelink;
import com.navinfo.onemap.det.sdkpbf.proto.crowdsource.Hadlanemarklink;
@ -48,7 +47,7 @@ public class RealmUtils {
private static RealmUtils instance;
private Realm realm;
private RealmConfiguration realmConfiguration;
private String defaultDir = NILayerManager.defaultDir;
private String defaultDir = "";//NILayerManager.defaultDir;
private String realmName;
private final String NAME = "name";

View File

@ -1,331 +1,331 @@
package com.navinfo.collect.library.map;
import android.app.Activity;
import android.content.Context;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.location.Location;
import android.os.Environment;
import android.text.TextPaint;
import android.util.Log;
import android.widget.TextView;
import android.widget.Toast;
import com.badlogic.gdx.maps.MapGroupLayer;
import com.navinfo.collect.library.R;
import com.navinfo.collect.library.map.layers.NIPolygonLayer;
import com.navinfo.collect.library.map.source.NavinfoMapRastorTileSource;
import com.navinfo.collect.library.map.source.NavinfoMultiMapFileTileSource;
import com.navinfo.collect.library.utils.DistanceUtil;
import com.navinfo.collect.library.utils.GeometryTools;
import com.navinfo.collect.library.utils.StringUtil;
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.geom.Polygon;
import org.oscim.android.canvas.AndroidBitmap;
import org.oscim.backend.CanvasAdapter;
import org.oscim.backend.canvas.Bitmap;
import org.oscim.core.GeoPoint;
import org.oscim.core.MapPosition;
import org.oscim.event.Event;
import org.oscim.layers.Layer;
import org.oscim.layers.LocationLayer;
import org.oscim.layers.marker.ItemizedLayer;
import org.oscim.layers.marker.MarkerInterface;
import org.oscim.layers.marker.MarkerItem;
import org.oscim.layers.marker.MarkerSymbol;
import org.oscim.layers.tile.bitmap.BitmapTileLayer;
import org.oscim.layers.tile.vector.VectorTileLayer;
import org.oscim.layers.vector.geometries.Drawable;
import org.oscim.layers.vector.geometries.PointDrawable;
import org.oscim.layers.vector.geometries.PolygonDrawable;
import org.oscim.layers.vector.PathLayer;
import org.oscim.layers.vector.geometries.Style;
import org.oscim.map.Map;
import org.oscim.tiling.source.OkHttpEngine;
import java.io.File;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import okhttp3.Cache;
import okhttp3.OkHttpClient;
public class NILayerManager implements ItemizedLayer.OnItemGestureListener {
private Map vtmMap;
public static String defaultDir = Environment.getExternalStorageDirectory() + "/" + "NavinfoCollect";
private String defaultLocalMapPath = defaultDir + "/maps/";
//图层管理
private java.util.Map<String, Layer> layersMap = new HashMap<String, Layer>();
//默认marker图层
private ItemizedLayer mDefaultMarkerLayer;
//定位图层
private LocationLayer mLocationLayer;
private NIPolygonLayer mPolygonLayer;
private List<MarkerItem> mPathMakers = new ArrayList<>();
private Location mCurrentLocation; // 当前位置信息
public static final String MARQUEE_MARKER_LAYER = "MarqueeMarker";
private Context mCon;
private java.util.Map<String, Layer> vectorLayerMap; // 维护vector图层的map数据key为图层名称一般对应为矢量数据的数据源value为图层
public NILayerManager(Context context, Map vtmMap) {
this.vtmMap = vtmMap;
this.mCon = context;
//新增marker图标样式
AndroidBitmap mDefaultBitmap =
new AndroidBitmap(BitmapFactory.decodeResource(context.getResources(), R.mipmap.marker));
MarkerSymbol markerSymbol = new MarkerSymbol(mDefaultBitmap, MarkerSymbol.HotspotPlace.BOTTOM_CENTER);
//新增marker图层
mDefaultMarkerLayer = new ItemizedLayer(
vtmMap,
new ArrayList<MarkerInterface>(),
markerSymbol,
this
);
addLayer("defaultMarkerLayer", mDefaultMarkerLayer, NIMapView.LAYER_GROUPS.VECTOR.ordinal());
//定位图层
mLocationLayer = new LocationLayer(vtmMap);
addLayer("locationLayer", mLocationLayer, NIMapView.LAYER_GROUPS.ALLWAYS_SHOW_GROUP.ordinal());
if (this.vectorLayerMap == null) {
this.vectorLayerMap = new HashMap<>();
}
}
public Layer getRasterTileLayer(Context mContext, String url, String tilePath, boolean useCache) {
if (this.vtmMap == null) {
throw new IllegalStateException("无法获取到map对象");
}
OkHttpClient.Builder builder = new OkHttpClient.Builder();
NavinfoMapRastorTileSource mTileSource = NavinfoMapRastorTileSource.builder(url).tilePath(tilePath).httpFactory(new OkHttpEngine.OkHttpFactory(builder)).build();
// 如果使用缓存
if (useCache) {
File cacheDirectory = new File(defaultDir, "tiles-raster");
int cacheSize = 300 * 1024 * 1024; // 300 MB
Cache cache = new Cache(cacheDirectory, cacheSize);
builder.cache(cache);
}
// mTileSource.setHttpEngine(new OkHttpEngine.OkHttpFactory(builder));
// mTileSource.setHttpRequestHeaders(Collections.singletonMap("User-Agent", "vtm-android-example"));
// mTileSource.setCache(new TileCache(mContext, defaultDir, url.substring(url.indexOf(":")+1)));
BitmapTileLayer rasterLayer = new BitmapTileLayer(this.vtmMap, mTileSource);
return rasterLayer;
}
// 初始化请求在线底图数据
public Layer getDefaultVectorLayer(boolean useCache) {
OkHttpClient.Builder builder = new OkHttpClient.Builder();
if (useCache) {
// Cache the tiles into file system
File cacheDirectory = new File(defaultDir, "tiles-vector");
int cacheSize = 200 * 1024 * 1024; // 200 MB
Cache cache = new Cache(cacheDirectory, cacheSize);
builder.cache(cache);
}
NavinfoMultiMapFileTileSource tileSource = NavinfoMultiMapFileTileSource.builder()
.apiKey("4wTLZyXcQym31pxC_HGy7Q") // Put a proper API key
.httpFactory(new OkHttpEngine.OkHttpFactory(builder))
//.locale("en")
.build();
HashMap<String, String> headerMap = new HashMap<>();
headerMap.put("token", "eyJhbGciOiJIUzI1NiJ9.eyJjbGllbnRJZCI6MTAzLCJ1c2VyTmFtZSI6ImFkbWluIiwidXNlcklkIjoxLCJ1c2VyR3JvdXAiOiLnoJTlj5Hpg6giLCJvcmdJZCI6MSwiaWF0IjoxNjMwOTk4MzI5LCJleHAiOjE2MzEwODQ3Mjl9.0wFm8mAA9dCC2FmZj-u1dhxTFDRYx8AqVnh2C88hitk");
tileSource.setHttpRequestHeaders(headerMap);
VectorTileLayer l = new VectorTileLayer(this.vtmMap, tileSource);
return l;
}
public void addLayer(String tag, Layer layer) {
if (!layersMap.containsKey(tag)) {
layersMap.put(tag, layer);
vtmMap.layers().add(layer);
}
}
public void addLayer(String tag, Layer layer, int group) {
if (!layersMap.containsKey(tag)) {
layersMap.put(tag, layer);
vtmMap.layers().add(layer, group);
}
}
public void addLayer(int index, String tag, Layer layer) {
if (!layersMap.containsKey(tag)) {
layersMap.put(tag, layer);
vtmMap.layers().add(index, layer);
}
}
public boolean containsLayer(String tag) {
return layersMap.containsKey(tag);
}
public Layer getLayer(String tag) {
return layersMap.get(tag);
}
public void removeLayer(String tag) {
if (layersMap.containsKey(tag)) {
Layer layer = layersMap.remove(tag);
vtmMap.layers().remove(layer);
}
}
/**
* 返回默认marker图层
*
* @return mDefaultMarkerLayer
*/
public ItemizedLayer getDefaultMarkerLayer() {
return mDefaultMarkerLayer;
}
/**
* 返回定位图层
*
* @return mLocationLayer
*/
public LocationLayer getLocationLayer() {
return mLocationLayer;
}
@Override
public boolean onItemSingleTapUp(int index, Object item) {
return false;
}
@Override
public boolean onItemLongPress(int index, Object item) {
return false;
}
/**
* 定位
* @param lon
* @param lat
* @param time
*/
public void jumpToPosition(double lon, double lat, long time) {
MapPosition mapPosition = vtmMap.getMapPosition();
mapPosition.setPosition(lat, lon);
vtmMap.animator().animateTo(time, mapPosition);
}
/**
* 定位
* @param lon
* @param lat
* @param zoomLevel
*/
public void jumpToPosition(double lon, double lat, int zoomLevel) {
MapPosition mapPosition = vtmMap.getMapPosition();
if (mapPosition.getZoomLevel() < zoomLevel) {
mapPosition.setZoomLevel(zoomLevel);
}
mapPosition.setPosition(lat, lon);
vtmMap.animator().animateTo(300, mapPosition);
}
public void addMarker2MarkerLayer(MarkerInterface markerItem, Bitmap defaultBitmap, String layerName, int layerGroup) {
if (markerItem == null) {
return;
}
if (vectorLayerMap != null) {
if (!vectorLayerMap.containsKey(layerName) || vectorLayerMap.get(layerName) == null) {
MarkerSymbol symbol = new MarkerSymbol(defaultBitmap, MarkerSymbol.HotspotPlace.BOTTOM_CENTER);
vectorLayerMap.put(layerName, new ItemizedLayer(vtmMap, symbol));
}
ItemizedLayer itemizedLayer = (ItemizedLayer) vectorLayerMap.get(layerName);
itemizedLayer.addItem(markerItem);
if (!vtmMap.layers().contains(itemizedLayer)) {
vtmMap.layers().add(itemizedLayer, layerGroup);
}
itemizedLayer.update();
}
}
public void addMarker2MarkerLayer(MarkerInterface markerItem, Bitmap defaultBitmap, String layerName, int layerGroup, ItemizedLayer.OnItemGestureListener listener) {
if (markerItem == null) {
return;
}
if (vectorLayerMap != null) {
if (!vectorLayerMap.containsKey(layerName) || vectorLayerMap.get(layerName) == null) {
MarkerSymbol symbol = new MarkerSymbol(defaultBitmap, MarkerSymbol.HotspotPlace.BOTTOM_CENTER);
vectorLayerMap.put(layerName, new ItemizedLayer(vtmMap, new ArrayList<MarkerInterface>(), symbol, listener));
}
ItemizedLayer itemizedLayer = (ItemizedLayer) vectorLayerMap.get(layerName);
itemizedLayer.addItem(markerItem);
if (!vtmMap.layers().contains(itemizedLayer)) {
vtmMap.layers().add(itemizedLayer, layerGroup);
}
itemizedLayer.update();
}
}
//删除marker
public void removeMarker(MarkerItem markerItem) {
if (vectorLayerMap != null && vectorLayerMap.containsKey("Marker")) {
ItemizedLayer itemizedLayer = (ItemizedLayer) vectorLayerMap.get("Marker");
if (itemizedLayer.getItemList() != null && itemizedLayer.getItemList().size() > 0) {
itemizedLayer.removeItem(markerItem);
}
}
}
/**
* @param markerItem marker
* @param layerName 图层
*/
public void removeMarker(MarkerItem markerItem, String layerName) {
if (vectorLayerMap != null && layerName != null && vectorLayerMap.containsKey(layerName)) {
ItemizedLayer itemizedLayer = (ItemizedLayer) vectorLayerMap.get(layerName);
if (itemizedLayer.getItemList() != null && itemizedLayer.getItemList().size() > 0) {
itemizedLayer.removeItem(markerItem);
}
}
}
/**
* 在地图中心增加marker
*/
public void showEditMapGraphical(String geometry, int type) {
}
//增加marker
public MarkerItem addMarker(GeoPoint geopoint, Bitmap bitmap) {
if (geopoint != null && bitmap != null) {
MarkerItem markerItem = new MarkerItem(StringUtil.Companion.createUUID(), "", geopoint.getLatitude() + "," + geopoint.getLongitude(), geopoint);
MarkerSymbol markerSymbol = new MarkerSymbol(bitmap, MarkerSymbol.HotspotPlace.BOTTOM_CENTER);
markerItem.setMarker(markerSymbol);
addMarker2MarkerLayer(markerItem, bitmap, "", NIMapView.LAYER_GROUPS.OTHER.ordinal());
return markerItem;
}
return null;
}
public Location getCurrentLocation() {
return mCurrentLocation;
}
}
//package com.navinfo.collect.library.map;
//
//import android.app.Activity;
//import android.content.Context;
//import android.graphics.BitmapFactory;
//import android.graphics.Color;
//import android.location.Location;
//import android.os.Environment;
//import android.text.TextPaint;
//import android.util.Log;
//import android.widget.TextView;
//import android.widget.Toast;
//
//import com.badlogic.gdx.maps.MapGroupLayer;
//import com.navinfo.collect.library.R;
//import com.navinfo.collect.library.map.layers.NIPolygonLayer;
//import com.navinfo.collect.library.map.source.NavinfoMapRastorTileSource;
//import com.navinfo.collect.library.map.source.NavinfoMultiMapFileTileSource;
//import com.navinfo.collect.library.utils.DistanceUtil;
//import com.navinfo.collect.library.utils.GeometryTools;
//import com.navinfo.collect.library.utils.StringUtil;
//
//import org.locationtech.jts.geom.Geometry;
//import org.locationtech.jts.geom.Polygon;
//import org.oscim.android.canvas.AndroidBitmap;
//import org.oscim.backend.CanvasAdapter;
//import org.oscim.backend.canvas.Bitmap;
//import org.oscim.core.GeoPoint;
//import org.oscim.core.MapPosition;
//import org.oscim.event.Event;
//import org.oscim.layers.Layer;
//import org.oscim.layers.LocationLayer;
//import org.oscim.layers.marker.ItemizedLayer;
//import org.oscim.layers.marker.MarkerInterface;
//import org.oscim.layers.marker.MarkerItem;
//import org.oscim.layers.marker.MarkerSymbol;
//import org.oscim.layers.tile.bitmap.BitmapTileLayer;
//import org.oscim.layers.tile.vector.VectorTileLayer;
//import org.oscim.layers.vector.geometries.Drawable;
//import org.oscim.layers.vector.geometries.PointDrawable;
//import org.oscim.layers.vector.geometries.PolygonDrawable;
//import org.oscim.layers.vector.PathLayer;
//import org.oscim.layers.vector.geometries.Style;
//import org.oscim.map.Map;
//import org.oscim.tiling.source.OkHttpEngine;
//
//import java.io.File;
//import java.math.BigDecimal;
//import java.util.ArrayList;
//import java.util.HashMap;
//import java.util.List;
//
//import okhttp3.Cache;
//import okhttp3.OkHttpClient;
//
//public class NILayerManager implements ItemizedLayer.OnItemGestureListener {
// private Map vtmMap;
// public static String defaultDir = Environment.getExternalStorageDirectory() + "/" + "NavinfoCollect";
// private String defaultLocalMapPath = defaultDir + "/maps/";
// //图层管理
// private java.util.Map<String, Layer> layersMap = new HashMap<String, Layer>();
// //默认marker图层
// private ItemizedLayer mDefaultMarkerLayer;
// //定位图层
// private LocationLayer mLocationLayer;
// private NIPolygonLayer mPolygonLayer;
// private List<MarkerItem> mPathMakers = new ArrayList<>();
// private Location mCurrentLocation; // 当前位置信息
//
// public static final String MARQUEE_MARKER_LAYER = "MarqueeMarker";
//
// private Context mCon;
//
// private java.util.Map<String, Layer> vectorLayerMap; // 维护vector图层的map数据key为图层名称一般对应为矢量数据的数据源value为图层
//
// public NILayerManager(Context context, Map vtmMap) {
// this.vtmMap = vtmMap;
// this.mCon = context;
//
// //新增marker图标样式
// AndroidBitmap mDefaultBitmap =
// new AndroidBitmap(BitmapFactory.decodeResource(context.getResources(), R.mipmap.marker));
// MarkerSymbol markerSymbol = new MarkerSymbol(mDefaultBitmap, MarkerSymbol.HotspotPlace.BOTTOM_CENTER);
// //新增marker图层
// mDefaultMarkerLayer = new ItemizedLayer(
// vtmMap,
// new ArrayList<MarkerInterface>(),
// markerSymbol,
// this
// );
// addLayer("defaultMarkerLayer", mDefaultMarkerLayer, NIMapView.LAYER_GROUPS.VECTOR.ordinal());
//
// //定位图层
// mLocationLayer = new LocationLayer(vtmMap);
// addLayer("locationLayer", mLocationLayer, NIMapView.LAYER_GROUPS.ALLWAYS_SHOW_GROUP.ordinal());
//
// if (this.vectorLayerMap == null) {
// this.vectorLayerMap = new HashMap<>();
// }
// }
//
// public Layer getRasterTileLayer(Context mContext, String url, String tilePath, boolean useCache) {
// if (this.vtmMap == null) {
// throw new IllegalStateException("无法获取到map对象");
// }
// OkHttpClient.Builder builder = new OkHttpClient.Builder();
// NavinfoMapRastorTileSource mTileSource = NavinfoMapRastorTileSource.builder(url).tilePath(tilePath).httpFactory(new OkHttpEngine.OkHttpFactory(builder)).build();
// // 如果使用缓存
// if (useCache) {
// File cacheDirectory = new File(defaultDir, "tiles-raster");
// int cacheSize = 300 * 1024 * 1024; // 300 MB
// Cache cache = new Cache(cacheDirectory, cacheSize);
// builder.cache(cache);
// }
//
//// mTileSource.setHttpEngine(new OkHttpEngine.OkHttpFactory(builder));
//// mTileSource.setHttpRequestHeaders(Collections.singletonMap("User-Agent", "vtm-android-example"));
//// mTileSource.setCache(new TileCache(mContext, defaultDir, url.substring(url.indexOf(":")+1)));
//
// BitmapTileLayer rasterLayer = new BitmapTileLayer(this.vtmMap, mTileSource);
// return rasterLayer;
// }
//
// // 初始化请求在线底图数据
// public Layer getDefaultVectorLayer(boolean useCache) {
// OkHttpClient.Builder builder = new OkHttpClient.Builder();
// if (useCache) {
// // Cache the tiles into file system
// File cacheDirectory = new File(defaultDir, "tiles-vector");
// int cacheSize = 200 * 1024 * 1024; // 200 MB
// Cache cache = new Cache(cacheDirectory, cacheSize);
// builder.cache(cache);
// }
//
// NavinfoMultiMapFileTileSource tileSource = NavinfoMultiMapFileTileSource.builder()
// .apiKey("4wTLZyXcQym31pxC_HGy7Q") // Put a proper API key
// .httpFactory(new OkHttpEngine.OkHttpFactory(builder))
// //.locale("en")
// .build();
// HashMap<String, String> headerMap = new HashMap<>();
// headerMap.put("token", "eyJhbGciOiJIUzI1NiJ9.eyJjbGllbnRJZCI6MTAzLCJ1c2VyTmFtZSI6ImFkbWluIiwidXNlcklkIjoxLCJ1c2VyR3JvdXAiOiLnoJTlj5Hpg6giLCJvcmdJZCI6MSwiaWF0IjoxNjMwOTk4MzI5LCJleHAiOjE2MzEwODQ3Mjl9.0wFm8mAA9dCC2FmZj-u1dhxTFDRYx8AqVnh2C88hitk");
// tileSource.setHttpRequestHeaders(headerMap);
// VectorTileLayer l = new VectorTileLayer(this.vtmMap, tileSource);
// return l;
// }
//
// public void addLayer(String tag, Layer layer) {
// if (!layersMap.containsKey(tag)) {
// layersMap.put(tag, layer);
// vtmMap.layers().add(layer);
// }
// }
//
//
// public void addLayer(String tag, Layer layer, int group) {
// if (!layersMap.containsKey(tag)) {
// layersMap.put(tag, layer);
// vtmMap.layers().add(layer, group);
// }
// }
//
// public void addLayer(int index, String tag, Layer layer) {
// if (!layersMap.containsKey(tag)) {
// layersMap.put(tag, layer);
// vtmMap.layers().add(index, layer);
// }
// }
//
// public boolean containsLayer(String tag) {
// return layersMap.containsKey(tag);
// }
//
// public Layer getLayer(String tag) {
// return layersMap.get(tag);
// }
//
// public void removeLayer(String tag) {
// if (layersMap.containsKey(tag)) {
// Layer layer = layersMap.remove(tag);
// vtmMap.layers().remove(layer);
// }
// }
//
// /**
// * 返回默认marker图层
// *
// * @return mDefaultMarkerLayer
// */
// public ItemizedLayer getDefaultMarkerLayer() {
// return mDefaultMarkerLayer;
// }
//
// /**
// * 返回定位图层
// *
// * @return mLocationLayer
// */
// public LocationLayer getLocationLayer() {
// return mLocationLayer;
// }
//
//
// @Override
// public boolean onItemSingleTapUp(int index, Object item) {
// return false;
// }
//
// @Override
// public boolean onItemLongPress(int index, Object item) {
// return false;
// }
//
// /**
// * 定位
// * @param lon
// * @param lat
// * @param time
// */
// public void jumpToPosition(double lon, double lat, long time) {
// MapPosition mapPosition = vtmMap.getMapPosition();
// mapPosition.setPosition(lat, lon);
// vtmMap.animator().animateTo(time, mapPosition);
// }
//
// /**
// * 定位
// * @param lon
// * @param lat
// * @param zoomLevel
// */
// public void jumpToPosition(double lon, double lat, int zoomLevel) {
// MapPosition mapPosition = vtmMap.getMapPosition();
// if (mapPosition.getZoomLevel() < zoomLevel) {
// mapPosition.setZoomLevel(zoomLevel);
// }
// mapPosition.setPosition(lat, lon);
// vtmMap.animator().animateTo(300, mapPosition);
// }
//
// public void addMarker2MarkerLayer(MarkerInterface markerItem, Bitmap defaultBitmap, String layerName, int layerGroup) {
// if (markerItem == null) {
// return;
// }
// if (vectorLayerMap != null) {
// if (!vectorLayerMap.containsKey(layerName) || vectorLayerMap.get(layerName) == null) {
// MarkerSymbol symbol = new MarkerSymbol(defaultBitmap, MarkerSymbol.HotspotPlace.BOTTOM_CENTER);
// vectorLayerMap.put(layerName, new ItemizedLayer(vtmMap, symbol));
// }
//
// ItemizedLayer itemizedLayer = (ItemizedLayer) vectorLayerMap.get(layerName);
// itemizedLayer.addItem(markerItem);
// if (!vtmMap.layers().contains(itemizedLayer)) {
// vtmMap.layers().add(itemizedLayer, layerGroup);
// }
// itemizedLayer.update();
// }
// }
//
// public void addMarker2MarkerLayer(MarkerInterface markerItem, Bitmap defaultBitmap, String layerName, int layerGroup, ItemizedLayer.OnItemGestureListener listener) {
// if (markerItem == null) {
// return;
// }
// if (vectorLayerMap != null) {
// if (!vectorLayerMap.containsKey(layerName) || vectorLayerMap.get(layerName) == null) {
// MarkerSymbol symbol = new MarkerSymbol(defaultBitmap, MarkerSymbol.HotspotPlace.BOTTOM_CENTER);
// vectorLayerMap.put(layerName, new ItemizedLayer(vtmMap, new ArrayList<MarkerInterface>(), symbol, listener));
// }
//
// ItemizedLayer itemizedLayer = (ItemizedLayer) vectorLayerMap.get(layerName);
// itemizedLayer.addItem(markerItem);
// if (!vtmMap.layers().contains(itemizedLayer)) {
// vtmMap.layers().add(itemizedLayer, layerGroup);
// }
// itemizedLayer.update();
// }
// }
//
// //删除marker
// public void removeMarker(MarkerItem markerItem) {
// if (vectorLayerMap != null && vectorLayerMap.containsKey("Marker")) {
// ItemizedLayer itemizedLayer = (ItemizedLayer) vectorLayerMap.get("Marker");
// if (itemizedLayer.getItemList() != null && itemizedLayer.getItemList().size() > 0) {
// itemizedLayer.removeItem(markerItem);
// }
// }
// }
//
// /**
// * @param markerItem marker
// * @param layerName 图层
// */
// public void removeMarker(MarkerItem markerItem, String layerName) {
// if (vectorLayerMap != null && layerName != null && vectorLayerMap.containsKey(layerName)) {
// ItemizedLayer itemizedLayer = (ItemizedLayer) vectorLayerMap.get(layerName);
// if (itemizedLayer.getItemList() != null && itemizedLayer.getItemList().size() > 0) {
// itemizedLayer.removeItem(markerItem);
// }
// }
// }
//
//
// /**
// * 在地图中心增加marker
// */
// public void showEditMapGraphical(String geometry, int type) {
//
// }
//
// //增加marker
// public MarkerItem addMarker(GeoPoint geopoint, Bitmap bitmap) {
// if (geopoint != null && bitmap != null) {
//
// MarkerItem markerItem = new MarkerItem(StringUtil.Companion.createUUID(), "", geopoint.getLatitude() + "," + geopoint.getLongitude(), geopoint);
//
// MarkerSymbol markerSymbol = new MarkerSymbol(bitmap, MarkerSymbol.HotspotPlace.BOTTOM_CENTER);
//
// markerItem.setMarker(markerSymbol);
//
// addMarker2MarkerLayer(markerItem, bitmap, "", NIMapView.LAYER_GROUPS.OTHER.ordinal());
//
// return markerItem;
// }
//
// return null;
// }
//
// public Location getCurrentLocation() {
// return mCurrentLocation;
// }
//
//}

View File

@ -1,8 +0,0 @@
package com.navinfo.collect.library.map
import android.location.Location
class NILocation(provider: String) : Location(provider) {
var radius = 0f
}

View File

@ -1,386 +1,330 @@
package com.navinfo.collect.library.map;
import android.graphics.Bitmap;
import android.graphics.Rect;
import android.view.MotionEvent;
import android.view.View;
import com.navinfo.collect.library.utils.CacheTileProgress;
import com.navinfo.collect.library.utils.TileDownloader;
import com.yanzhenjie.kalle.Kalle;
import com.yanzhenjie.kalle.download.Download;
import org.oscim.core.GeoPoint;
import org.oscim.core.MapPosition;
import org.oscim.layers.Layer;
import org.oscim.layers.tile.bitmap.BitmapTileLayer;
import org.oscim.map.Map;
import org.oscim.tiling.source.UrlTileSource;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.Executors;
import java.util.concurrent.FutureTask;
import java.util.concurrent.ScheduledExecutorService;
/**
* 定义 NavinfoMap 地图对象的操作方法与接口
*/
public class NIMap {
/**
*
*/
private Map map;
/**
* 地图控件
*/
private NIMapView mMapView;
/**
* 指北针显隐
*/
private boolean enableCompassImage = true;
/**
* 用户位置显示图层
* */
// private NaviLocationLayer locationLayer;
/**
* 构造函数
*/
public NIMap(NIMapView niMapView) {
this.mMapView = niMapView;
this.map = mMapView.getVtmMap();
}
/**
* 获取地图的当前状态
*
* @return
*/
public Map getVtmMap() {
return map;
}
/**
* 获取地图最大缩放级别
*
* @return
*/
public float getMaxZoomLevel() {
return map.viewport().getMaxZoomLevel();
}
/**
* 获取地图最小缩放级别
*
* @return
*/
public float getMinZoomLevel() {
return map.viewport().getMinZoomLevel();
}
/**
* 设置指南针是否显示
*
* @param enable
*/
public void setCompassEnable(boolean enable) {
this.enableCompassImage = enable;
if (mMapView != null && mMapView.getCompassImage() != null) {
mMapView.getCompassImage().setVisibility(enable ? View.VISIBLE : View.GONE);
mMapView.getCompassImage().setEnabled(enable);
}
}
/**
* 获取指北针显隐控制
*
* @return true 显示 false 隐藏
*/
public boolean isEnableCompassImage() {
return enableCompassImage;
}
/**
* 设置指南针自定义图标
*
* @param icon
*/
public void setCompassIcon(Bitmap icon) {
if (mMapView != null && mMapView.getCompassImage() != null) {
mMapView.getCompassImage().setImageBitmap(icon);
}
}
/**
* 设置地图显示大小等级
*
* @param level
*/
public void setFontSizeLevel(int level) {
}
/**
* 设置地图最大以及最小缩放级别
*
* @param max
* @param min
*/
public void setMaxAndMinZoomLevel(int max, int min) {
map.viewport().setMaxZoomLevel(max);
map.viewport().setMinZoomLevel(min);
}
/**
* 放大
*
* @param animate 是否动画过渡
*/
public void zoomIn(boolean animate) {
MapPosition mapPosition = map.getMapPosition();
mapPosition.setZoom(mapPosition.getZoom() + 1);
if (animate) {
map.animator().animateTo(mapPosition);
} else {
map.setMapPosition(mapPosition);
}
}
/**
* 缩小地图
*
* @param animate 是否动画过渡
*/
public void zoomOut(boolean animate) {
MapPosition mapPosition = map.getMapPosition();
mapPosition.setZoom(mapPosition.getZoom() - 1);
if (animate) {
map.animator().animateTo(mapPosition);
} else {
map.setMapPosition(mapPosition);
}
}
/**
* 设置定位数据, 只有先允许定位图层后设置数据才会生效参见 setMyLocationEnabled(boolean)
*
* @param data
*/
// public void setMyLocationData(Location data) {
// if (locationLayer == null) {
// return;
// }
// locationLayer.setPosition(data.getLatitude(), data.getLongitude(), data.getAccuracy());
//package com.navinfo.collect.library.map;
//
//import android.graphics.Bitmap;
//import android.graphics.Rect;
//import android.view.View;
//
//import com.navinfo.collect.library.utils.CacheTileProgress;
//import com.navinfo.collect.library.utils.TileDownloader;
//import com.yanzhenjie.kalle.download.Download;
//
//import org.oscim.core.GeoPoint;
//import org.oscim.core.MapPosition;
//import org.oscim.layers.Layer;
//import org.oscim.layers.tile.bitmap.BitmapTileLayer;
//import org.oscim.map.Map;
//import org.oscim.tiling.source.UrlTileSource;
//
//import java.util.ArrayList;
//import java.util.List;
//import java.util.concurrent.Callable;
//import java.util.concurrent.Executors;
//import java.util.concurrent.FutureTask;
//import java.util.concurrent.ScheduledExecutorService;
//
///**
// * 定义 NavinfoMap 地图对象的操作方法与接口
// */
//public class NIMap {
// /**
// *
// */
// private Map map;
// /**
// * 地图控件
// */
// private NIMapView mMapView;
// /**
// * 指北针显隐
// */
// private boolean enableCompassImage = true;
//
// /**
// * 用户位置显示图层
// * */
//// private NaviLocationLayer locationLayer;
//
// /**
// * 构造函数
// */
// public NIMap(NIMapView niMapView) {
// this.mMapView = niMapView;
// this.map = mMapView.getVtmMap();
// }
// public void setMyLocationData(double lat, double lon, float accuracy) {
// if (locationLayer == null) {
// return;
// }
// locationLayer.setPosition(lat, lon, accuracy);
//
// /**
// * 获取地图的当前状态
// *
// * @return
// */
// public Map getVtmMap() {
// return map;
// }
/**
* 设置是否允许定位图层
*
* @param enabled
*/
// public void setMyLocationEnabled(Context mContext, boolean enabled) {
// initLocaitonLayer(mContext);
// locationLayer.setEnabled(enabled);
//
// /**
// * 获取地图最大缩放级别
// *
// * @return
// */
// public float getMaxZoomLevel() {
// return map.viewport().getMaxZoomLevel();
// }
// private void initLocaitonLayer(Context mContext) {
// if (map == null) {
// throw new IllegalStateException("map不可用无法显示当前位置");
// }
// if (locationLayer == null) {
// locationLayer = new NaviLocationLayer(mContext, map);
//
// /**
// * 获取地图最小缩放级别
// *
// * @return
// */
// public float getMinZoomLevel() {
//
// return map.viewport().getMinZoomLevel();
// }
//
// /**
// * 设置指南针是否显示
// *
// * @param enable
// */
// public void setCompassEnable(boolean enable) {
// this.enableCompassImage = enable;
// if (mMapView != null && mMapView.getCompassImage() != null) {
// mMapView.getCompassImage().setVisibility(enable ? View.VISIBLE : View.GONE);
// mMapView.getCompassImage().setEnabled(enable);
// }
// }
/**
* 设置地图
* */
public void setMapPosition(double latitude, double longitude, int zoomLevel) {
double scale = 1 << zoomLevel;
getVtmMap().setMapPosition(latitude, longitude, scale);
}
public void animateMapPosition(double latitude, double longitude, int zoomLevel, int duration) {
if (duration < 0) {
duration = 500;
}
if (zoomLevel <= 0) {
zoomLevel = getVtmMap().getMapPosition().zoomLevel;
}
double scale = 1 << zoomLevel;
MapPosition mapPosition = new MapPosition(latitude, longitude, scale);
getVtmMap().animator().animateTo(duration, mapPosition);
}
/**
* 下载离线矢量地图
* */
public void downloadVectorMap(String url, DownloadProgress downloadProgress) {
Kalle.Download.get(url).directory(NILayerManager.defaultDir).onProgress(new Download.ProgressBar() {
@Override
public void onProgress(int progress, long byteCount, long speed) {
downloadProgress.onProgress(progress, byteCount, speed);
}
});
}
/**
* 缓存urlTilesource对应的数据
* */
public List<FutureTask> cacheUrlTileMap(Rect rect, int minZoomLevel, int maxZoomLevel, CacheTileProgress progress) {
List<Layer> layerList = getVtmMap().layers();
List<UrlTileSource> urlTileSourceList = new ArrayList<>();
if (layerList!=null&&!layerList.isEmpty()) {
for (int i = 0; i < layerList.size(); i++) {
Layer layer = layerList.get(i);
if (layer instanceof BitmapTileLayer && ((BitmapTileLayer) layer).getTileSource() instanceof UrlTileSource) {
UrlTileSource urlTileSource = (UrlTileSource) ((BitmapTileLayer) layer).getTileSource();
urlTileSourceList.add(urlTileSource);
}
}
}
// 根据rect获取对应的地理坐标
GeoPoint leftTopGeoPoint = map.viewport().fromScreenPoint(rect.left, rect.top);
GeoPoint rightBottomGeoPoint = map.viewport().fromScreenPoint(rect.right, rect.bottom);
ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
List<FutureTask> futureTaskList = new ArrayList<>();
progress.setLayerCount(urlTileSourceList.size());
for (int i = 0; i < urlTileSourceList.size(); i++) {
UrlTileSource urlTileSource = urlTileSourceList.get(i);
int finalI = i;
progress.setLayerId(i);
Callable callable = TileDownloader.getInstance().downloadRasterTile(urlTileSource, leftTopGeoPoint, rightBottomGeoPoint, (byte) minZoomLevel, (byte) maxZoomLevel, progress);
FutureTask futureTask = new FutureTask(callable);
futureTaskList.add(futureTask);
}
if (futureTaskList!=null&&!futureTaskList.isEmpty()){
for (int i = 0; i < futureTaskList.size(); i++) {
scheduledExecutorService.submit(futureTaskList.get(i));
}
scheduledExecutorService.shutdown();
}
return futureTaskList;
}
public void cancelCacheTileMap() {
TileDownloader.getInstance().setCanDownloadRasterTile(false);
}
public interface DownloadProgress {
Download.ProgressBar DEFAULT = new Download.ProgressBar() {
@Override
public void onProgress(int progress, long byteCount, long speed) {
}
};
/**
* Download onProgress changes.
*/
void onProgress(int progress, long byteCount, long speed);
}
/**
* 设置地图单击事件监听者
*
* @param listener
*/
public void setOnMapClickListener(OnMapClickListener listener) {
mMapView.setOnMapClickListener(listener);
}
/**
* 设置地图双击事件监听者
*
* @param listener
*/
public void setOnMapDoubleClickListener(OnMapDoubleClickListener listener) {
mMapView.setOnMapDoubleClickListener(listener);
}
/**
* 设置地图长按事件监听者
*
* @param listener
*/
public void setOnMapLongClickListener(OnMapLongClickListener listener) {
mMapView.setOnMapLongClickListener(listener);
}
/**
* @param listener
*/
public void setOnMapTouchListener(OnMapTouchListener listener) {
mMapView.setOnMapTouchListener(listener);
}
/**
* 地图单击事件监听接口
*/
public static interface OnMapClickListener {
/**
* 地图单击事件回调函数
*
* @param point
*/
void onMapClick(GeoPoint point);
/**
* 地图内 Poi 单击事件回调函数
*
* @param poi
*/
void onMapPoiClick(GeoPoint poi);
}
/**
* 地图双击事件监听接口
*/
public static interface OnMapDoubleClickListener {
/**
* 地图双击事件监听回调函数
*
* @param point
*/
void onMapDoubleClick(GeoPoint point);
}
/**
* 地图长按事件监听接口
*/
public static interface OnMapLongClickListener {
/**
* 地图长按事件监听回调函数
*
* @param point
*/
void onMapLongClick(GeoPoint point);
}
/**
* 用户触摸地图时回调接口
*/
public static interface OnMapTouchListener {
/**
* 当用户触摸地图时回调函数
*
* @param event
*/
void onTouch(MotionEvent event);
}
}
//
// /**
// * 获取指北针显隐控制
// *
// * @return true 显示 false 隐藏
// */
// public boolean isEnableCompassImage() {
// return enableCompassImage;
// }
//
// /**
// * 设置指南针自定义图标
// *
// * @param icon
// */
// public void setCompassIcon(Bitmap icon) {
// if (mMapView != null && mMapView.getCompassImage() != null) {
// mMapView.getCompassImage().setImageBitmap(icon);
// }
// }
//
//
// /**
// * 设置地图显示大小等级
// *
// * @param level
// */
// public void setFontSizeLevel(int level) {
//
// }
//
// /**
// * 设置地图最大以及最小缩放级别
// *
// * @param max
// * @param min
// */
// public void setMaxAndMinZoomLevel(int max, int min) {
// map.viewport().setMaxZoomLevel(max);
// map.viewport().setMinZoomLevel(min);
// }
//
// /**
// * 放大
// *
// * @param animate 是否动画过渡
// */
// public void zoomIn(boolean animate) {
// MapPosition mapPosition = map.getMapPosition();
// mapPosition.setZoom(mapPosition.getZoom() + 1);
// if (animate) {
// map.animator().animateTo(mapPosition);
// } else {
// map.setMapPosition(mapPosition);
// }
// }
//
// /**
// * 缩小地图
// *
// * @param animate 是否动画过渡
// */
// public void zoomOut(boolean animate) {
// MapPosition mapPosition = map.getMapPosition();
// mapPosition.setZoom(mapPosition.getZoom() - 1);
// if (animate) {
// map.animator().animateTo(mapPosition);
// } else {
// map.setMapPosition(mapPosition);
// }
// }
//
// /**
// * 设置定位数据, 只有先允许定位图层后设置数据才会生效参见 setMyLocationEnabled(boolean)
// *
// * @param data
// */
//// public void setMyLocationData(Location data) {
//// if (locationLayer == null) {
//// return;
//// }
//// locationLayer.setPosition(data.getLatitude(), data.getLongitude(), data.getAccuracy());
//// }
//
//// public void setMyLocationData(double lat, double lon, float accuracy) {
//// if (locationLayer == null) {
//// return;
//// }
//// locationLayer.setPosition(lat, lon, accuracy);
//// }
//
// /**
// * 设置是否允许定位图层
// *
// * @param enabled
// */
//// public void setMyLocationEnabled(Context mContext, boolean enabled) {
//// initLocaitonLayer(mContext);
//// locationLayer.setEnabled(enabled);
//// }
//
//// private void initLocaitonLayer(Context mContext) {
//// if (map == null) {
//// throw new IllegalStateException("map不可用无法显示当前位置");
//// }
//// if (locationLayer == null) {
//// locationLayer = new NaviLocationLayer(mContext, map);
//// }
//// }
//
// /**
// * 设置地图
// */
// public void setMapPosition(double latitude, double longitude, int zoomLevel) {
// double scale = 1 << zoomLevel;
// getVtmMap().setMapPosition(latitude, longitude, scale);
// }
//
// public void animateMapPosition(double latitude, double longitude, int zoomLevel, int duration) {
// if (duration < 0) {
// duration = 500;
// }
// if (zoomLevel <= 0) {
// zoomLevel = getVtmMap().getMapPosition().zoomLevel;
// }
// double scale = 1 << zoomLevel;
// MapPosition mapPosition = new MapPosition(latitude, longitude, scale);
// getVtmMap().animator().animateTo(duration, mapPosition);
// }
//
//// /**
//// * 下载离线矢量地图
//// * */
//// public void downloadVectorMap(String url, DownloadProgress downloadProgress) {
//// Kalle.Download.get(url).directory(NILayerManager.defaultDir).onProgress(new Download.ProgressBar() {
//// @Override
//// public void onProgress(int progress, long byteCount, long speed) {
//// downloadProgress.onProgress(progress, byteCount, speed);
//// }
//// });
//// }
//
// /**
// * 缓存urlTilesource对应的数据
// */
// public List<FutureTask> cacheUrlTileMap(Rect rect, int minZoomLevel, int maxZoomLevel, CacheTileProgress progress) {
// List<Layer> layerList = getVtmMap().layers();
// List<UrlTileSource> urlTileSourceList = new ArrayList<>();
// if (layerList != null && !layerList.isEmpty()) {
// for (int i = 0; i < layerList.size(); i++) {
// Layer layer = layerList.get(i);
// if (layer instanceof BitmapTileLayer && ((BitmapTileLayer) layer).getTileSource() instanceof UrlTileSource) {
// UrlTileSource urlTileSource = (UrlTileSource) ((BitmapTileLayer) layer).getTileSource();
// urlTileSourceList.add(urlTileSource);
// }
// }
// }
// // 根据rect获取对应的地理坐标
// GeoPoint leftTopGeoPoint = map.viewport().fromScreenPoint(rect.left, rect.top);
// GeoPoint rightBottomGeoPoint = map.viewport().fromScreenPoint(rect.right, rect.bottom);
// ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
// List<FutureTask> futureTaskList = new ArrayList<>();
// progress.setLayerCount(urlTileSourceList.size());
// for (int i = 0; i < urlTileSourceList.size(); i++) {
// UrlTileSource urlTileSource = urlTileSourceList.get(i);
// int finalI = i;
// progress.setLayerId(i);
// Callable callable = TileDownloader.getInstance().downloadRasterTile(urlTileSource, leftTopGeoPoint, rightBottomGeoPoint, (byte) minZoomLevel, (byte) maxZoomLevel, progress);
// FutureTask futureTask = new FutureTask(callable);
// futureTaskList.add(futureTask);
// }
//
// if (futureTaskList != null && !futureTaskList.isEmpty()) {
// for (int i = 0; i < futureTaskList.size(); i++) {
// scheduledExecutorService.submit(futureTaskList.get(i));
// }
// scheduledExecutorService.shutdown();
// }
// return futureTaskList;
// }
//
// public void cancelCacheTileMap() {
// TileDownloader.getInstance().setCanDownloadRasterTile(false);
// }
//
// public interface DownloadProgress {
//
// Download.ProgressBar DEFAULT = new Download.ProgressBar() {
// @Override
// public void onProgress(int progress, long byteCount, long speed) {
// }
// };
//
// /**
// * Download onProgress changes.
// */
// void onProgress(int progress, long byteCount, long speed);
// }
//
// /**
// * 设置地图单击事件监听者
// *
// * @param listener
// */
// public void setOnMapClickListener(OnMapClickListener listener) {
// mMapView.setOnMapClickListener(listener);
// }
//
// /**
// * 设置地图双击事件监听者
// *
// * @param listener
// */
// public void setOnMapDoubleClickListener(OnMapDoubleClickListener listener) {
// mMapView.setOnMapDoubleClickListener(listener);
// }
//
// /**
// * 设置地图长按事件监听者
// *
// * @param listener
// */
// public void setOnMapLongClickListener(OnMapLongClickListener listener) {
// mMapView.setOnMapLongClickListener(listener);
// }
//
// /**
// * @param listener
// */
// public void setOnMapTouchListener(OnMapTouchListener listener) {
// mMapView.setOnMapTouchListener(listener);
// }
//
//
//
//}

View File

@ -1,6 +1,7 @@
package com.navinfo.collect.library.map
import android.content.Context
import com.navinfo.collect.library.data.entity.LayerManager
import com.navinfo.collect.library.map.handler.*
import com.navinfo.collect.library.map.maphandler.MeasureLayerHandler
import com.navinfo.collect.library.map.handler.ViewportHandler
@ -15,35 +16,16 @@ open class NIMapController(
mapView: NIMapView? = null,
) {
private val mContext = context
internal var mMapView: NIMapView =
mapView ?: NIMapView(mContext, options)
var mMapView: NIMapView = mapView ?: NIMapView(mContext, options)
val animationHandler: AnimationHandler by lazy { AnimationHandler(mContext, mMapView) }
val markerHandle: MarkHandler by lazy { MarkHandler(mContext, mMapView) }
val locationLayerHandler: LocationLayerHandler by lazy {
LocationLayerHandler(
mContext,
mMapView
)
};
val lineHandler: LineHandler by lazy { LineHandler(mContext, mMapView) };
val polygonHandler: PolygonHandler by lazy { PolygonHandler(mContext, mMapView) };
val viewportHandler: ViewportHandler by lazy { ViewportHandler(mContext, mMapView) }
val measureLayerHandler: MeasureLayerHandler by lazy { MeasureLayerHandler(mContext, mMapView) };
val layerManagerHandler = LayerManagerHandler(mContext, mMapView)
val locationLayerHandler by lazy { LocationLayerHandler(mContext, mMapView) }
val animationHandler by lazy { AnimationHandler(mContext, mMapView) }
val markerHandle by lazy { MarkHandler(mContext, mMapView) }
val lineHandler by lazy { LineHandler(mContext, mMapView) }
val polygonHandler by lazy { PolygonHandler(mContext, mMapView) }
val viewportHandler by lazy { ViewportHandler(mContext, mMapView) }
val measureLayerHandler by lazy { MeasureLayerHandler(mContext, mMapView) }
/**
* 刷新地图
*/
fun upDateMap(redraw: Boolean = true) {
if (redraw) {
mMapView.vtmMap.events.fire(org.oscim.map.Map.CLEAR_EVENT, mMapView.vtmMap.mapPosition)
}
mMapView.vtmMap.updateMap(redraw)
}
open fun release() {
mMapView.onDestroy()
}
}

View File

@ -47,6 +47,8 @@ import org.oscim.tiling.source.mapfile.MultiMapFileTileSource;
import java.io.File;
/**
* 一个显示地图的视图View它负责从服务端获取地图数据它将会捕捉屏幕触控手势事件
*/
@ -93,14 +95,82 @@ public final class NIMapView extends RelativeLayout {
/**
* 地图图层管理器
*/
private NILayerManager mLayerManager;
private Layer baseRasterLayer, defaultVectorTileLayer, defaultVectorLabelLayer, gridLayer;
// private NILayerManager mLayerManager;
// private Layer baseRasterLayer, defaultVectorTileLayer, defaultVectorLabelLayer, gridLayer;
/**
* 地图网格图层
*/
// private Layer gridLayer;
protected Context mContext;
/**
* 地图状态信息
*/
private MapPreferences mPrefs;
protected String mapFilePath = Constant.ROOT_PATH+"/map";
// protected String mapFilePath = Constant.ROOT_PATH + "/map";
protected GroupLayer baseGroupLayer; // 用于盛放所有基础底图的图层组便于统一管理
/**
* 地图单击事件监听接口
*/
public interface OnMapClickListener {
/**
* 地图单击事件回调函数
*
* @param point
*/
void onMapClick(GeoPoint point);
/**
* 地图内 Poi 单击事件回调函数
*
* @param poi
*/
void onMapPoiClick(GeoPoint poi);
}
/**
* 地图双击事件监听接口
*/
public interface OnMapDoubleClickListener {
/**
* 地图双击事件监听回调函数
*
* @param point
*/
void onMapDoubleClick(GeoPoint point);
}
/**
* 地图长按事件监听接口
*/
public interface OnMapLongClickListener {
/**
* 地图长按事件监听回调函数
*
* @param point
*/
void onMapLongClick(GeoPoint point);
}
/**
* 用户触摸地图时回调接口
*/
public interface OnMapTouchListener {
/**
* 当用户触摸地图时回调函数
*
* @param event
*/
void onTouch(MotionEvent event);
}
public NIMapView(Context context, NIMapOptions options) {
this(context, null, 0);
this.options = options;
@ -110,22 +180,22 @@ public final class NIMapView extends RelativeLayout {
/**
* 地图的单击事件监听
*/
private NIMap.OnMapClickListener mapClickListener;
private OnMapClickListener mapClickListener;
/**
* 地图的双击事件监听
*/
private NIMap.OnMapDoubleClickListener mapDoubleClickListener;
private OnMapDoubleClickListener mapDoubleClickListener;
/**
* 地图的长按事件监听
*/
private NIMap.OnMapLongClickListener mapLongClickListener;
private OnMapLongClickListener mapLongClickListener;
/**
* 地图的触摸事件
*/
private NIMap.OnMapTouchListener touchListener;
private OnMapTouchListener touchListener;
public NIMapView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
@ -148,8 +218,7 @@ public final class NIMapView extends RelativeLayout {
// map = new NIMap(this);
compassImage = rootView.findViewById(R.id.navinfo_map_compass);
initMapGroup(); // 初始化图层组
mLayerManager = new NILayerManager(context, getVtmMap());
// mLayerManager = new NILayerManager(context, getVtmMap());
logoImage = rootView.findViewById(R.id.navinfo_map_logo);
mRotateAnimation = new NIRotateAnimation(compassImage);
@ -183,11 +252,11 @@ public final class NIMapView extends RelativeLayout {
NaviMapScaleBar naviMapScaleBar = new NaviMapScaleBar(getVtmMap());
naviMapScaleBar.initScaleBarLayer(GLViewport.Position.BOTTOM_LEFT, 25, 60);
if (gridLayer == null) {
gridLayer = new TileGridLayer(getVtmMap());
getVtmMap().layers().add(gridLayer, LAYER_GROUPS.ALLWAYS_SHOW_GROUP.groupIndex);
gridLayer.setEnabled(false);
}
// if (gridLayer == null) {
// gridLayer = new TileGridLayer(getVtmMap());
// getVtmMap().layers().add(gridLayer, LAYER_GROUPS.NAVIGATION.groupIndex);
//// gridLayer.setEnabled(true);
// }
compassImage.setOnClickListener(new OnClickListener() {
@Override
@ -229,9 +298,53 @@ public final class NIMapView extends RelativeLayout {
});
zoomLayout = rootView.findViewById(R.id.navinfo_map_zoom_layer);
initMap();
switchTileVectorLayerTheme(MAP_THEME.DEFAULT);
}
/**
* 切换 矢量图层 style
*/
public void switchTileVectorLayerTheme(MAP_THEME styleId) {
// 如果不包含vectorlayer则设置theme无效
boolean bHis = false;
for (Layer layer : getVtmMap().layers()) {
if (layer instanceof VectorTileLayer) {
bHis = true;
break;
}
}
if (!bHis) {
updateMap(true);
return;
}
if (styleId == null) {
getVtmMap().setTheme(new AssetsRenderTheme(mContext.getAssets(), "", "navdefault.xml"), true);
} else {
switch (styleId) {
case NEWTRON:
getVtmMap().setTheme(VtmThemes.NEWTRON, true);
break;
case OSMAGRAY:
getVtmMap().setTheme(VtmThemes.OSMAGRAY, true);
break;
case OSMARENDER:
getVtmMap().setTheme(VtmThemes.OSMARENDER, true);
break;
case TRONRENDER:
getVtmMap().setTheme(VtmThemes.TRONRENDER, true);
break;
default:
getVtmMap().setTheme(new AssetsRenderTheme(mContext.getAssets(), "", "editormarker.xml"), true);
break;
}
}
updateMap();
}
/**
* 地图初始化参数
*/
@ -250,197 +363,177 @@ public final class NIMapView extends RelativeLayout {
}
/**
* 初始化地图
*/
private void initMap() {
switchBaseMapType(BASE_MAP_TYPE.CYCLE_MAP);
switchTileVectorLayerTheme(MAP_THEME.DEFAULT);
initVectorTileLayer();
initMapLifeSource();
}
// /**
// * 增加作业渲染
// */
// LabelLayer labelLayer;
// /**
// * 作业数据图层
// */
// VectorTileLayer vectorTileLayer;
// /**
// * 作业数据渲染图层
// */
// MapLifeDBTileSource mapLifeDBTileSource;
// /**
// * 轨迹渲染图层
// */
// MapLifeNiLocationTileSource mapLifeNiLocationTileSource;
// /**
// * 轨迹数据图层
// */
// VectorTileLayer vectorNiLocationTileLayer;
// /**
// * 增加作业渲染
// */
// LabelLayer labelNiLocationLayer;
// public void initMapLifeSource() {
// mapLifeDBTileSource = new MapLifeDBTileSource(this.mContext, Constant.ROOT_PATH + "/coremap.db");
// mapLifeNiLocationTileSource = new MapLifeNiLocationTileSource(this.mContext, Constant.ROOT_PATH + "/coremap.db");
// vectorTileLayer = new VectorTileLayer(mapView.map(), mapLifeDBTileSource);
// vectorNiLocationTileLayer = new VectorTileLayer(mapView.map(), mapLifeNiLocationTileSource);
// mapView.map().layers().add(vectorNiLocationTileLayer, LAYER_GROUPS.VECTOR_TILE.groupIndex);
// mapView.map().layers().add(vectorTileLayer, LAYER_GROUPS.VECTOR_TILE.groupIndex);
// labelLayer = new LabelLayer(mapView.map(), vectorTileLayer, new LabelTileLoaderHook(), 15);
// mapView.map().layers().add(labelLayer, LAYER_GROUPS.VECTOR_TILE.groupIndex);
// labelNiLocationLayer = new LabelLayer(mapView.map(), vectorNiLocationTileLayer, new LabelTileLoaderHook(), 15);
// mapView.map().layers().add(labelNiLocationLayer, LAYER_GROUPS.VECTOR_TILE.groupIndex);
//
// switchTileVectorLayerTheme(null);
// mapView.map().updateMap(true);
// MapPosition mapPosition = new MapPosition();
// mapPosition.setZoomLevel(18);
// mapPosition.setPosition(40.091692296269144, 116.26712172082546);
// //116.26712172082546 40.091692296269144
// mapView.map().animator().animateTo(mapPosition);
// }
//
// public void dataLayerUpdate() {
// switchTileVectorLayerTheme(null);
// }
/**
* 增加作业渲染
* 初始化地图图层分组
*/
LabelLayer labelLayer;
/**
* 作业数据图层
*/
VectorTileLayer vectorTileLayer;
/**
* 作业数据渲染图层
*/
MapLifeDBTileSource mapLifeDBTileSource;
/**
* 轨迹渲染图层
*/
MapLifeNiLocationTileSource mapLifeNiLocationTileSource;
/**
* 轨迹数据图层
*/
VectorTileLayer vectorNiLocationTileLayer;
/**
* 增加作业渲染
*/
LabelLayer labelNiLocationLayer;
public void initMapLifeSource() {
mapLifeDBTileSource = new MapLifeDBTileSource(this.mContext, Constant.ROOT_PATH + "/coremap.db");
mapLifeNiLocationTileSource = new MapLifeNiLocationTileSource(this.mContext,Constant.ROOT_PATH + "/coremap.db");
vectorTileLayer = new VectorTileLayer(mapView.map(), mapLifeDBTileSource);
vectorNiLocationTileLayer = new VectorTileLayer(mapView.map(),mapLifeNiLocationTileSource);
mapView.map().layers().add(vectorNiLocationTileLayer,LAYER_GROUPS.VECTOR_TILE.groupIndex);
mapView.map().layers().add(vectorTileLayer,LAYER_GROUPS.VECTOR_TILE.groupIndex);
labelLayer = new LabelLayer(mapView.map(), vectorTileLayer, new LabelTileLoaderHook(), 15);
mapView.map().layers().add(labelLayer,LAYER_GROUPS.VECTOR_TILE.groupIndex);
labelNiLocationLayer = new LabelLayer(mapView.map(), vectorNiLocationTileLayer, new LabelTileLoaderHook(), 15);
mapView.map().layers().add(labelNiLocationLayer,LAYER_GROUPS.VECTOR_TILE.groupIndex);
switchTileVectorLayerTheme(null);
mapView.map().updateMap(true);
MapPosition mapPosition = new MapPosition();
mapPosition.setZoomLevel(18);
mapPosition.setPosition(40.091692296269144, 116.26712172082546);
//116.26712172082546 40.091692296269144
mapView.map().animator().animateTo(mapPosition);
}
public void dataLayerUpdate() {
switchTileVectorLayerTheme(null);
}
private void initMapGroup() {
for (LAYER_GROUPS groups : LAYER_GROUPS.values()) {
getVtmMap().layers().addGroup(groups.groupIndex);
}
}
/**
* 切换基础底图样式
*/
public void switchBaseMapType(BASE_MAP_TYPE type) {
if (baseRasterLayer != null) {
getVtmMap().layers().remove(baseRasterLayer);
baseRasterLayer = null;
getVtmMap().updateMap();
}
baseRasterLayer = mLayerManager.getRasterTileLayer(mContext, type.url, type.tilePath, true);
getVtmMap().layers().add(baseRasterLayer, LAYER_GROUPS.BASE_RASTER.groupIndex);
getVtmMap().updateMap();
}
/**
* 移除基础底图样式
*/
public void removeBaseMap() {
if (baseRasterLayer != null) {
getVtmMap().layers().remove(baseRasterLayer);
baseRasterLayer = null;
getVtmMap().updateMap();
}
}
// /**
// * 移除基础底图样式
// */
// public void removeBaseMap() {
// if (baseRasterLayer != null) {
// getVtmMap().layers().remove(baseRasterLayer);
// baseRasterLayer = null;
// getVtmMap().updateMap();
// }
// }
public void initVectorTileLayer(){
if (baseGroupLayer == null) {
baseGroupLayer = new GroupLayer(getVtmMap());
}
for (Layer layer : baseGroupLayer.layers) {
getVtmMap().layers().remove(layer);
}
baseGroupLayer.layers.clear();
// private void initVectorTileLayer() {
// if (baseGroupLayer == null) {
// baseGroupLayer = new GroupLayer(getVtmMap());
// }
// for (Layer layer : baseGroupLayer.layers) {
// getVtmMap().layers().remove(layer);
// }
// baseGroupLayer.layers.clear();
//
// File baseMapFolder = new File(mapFilePath);
// if (!baseMapFolder.exists()) {
// return;
// }
//
// File[] mapFileList = baseMapFolder.listFiles();
//
// if (mapFileList != null && mapFileList.length > 0) {
//
// MultiMapFileTileSource multiMapFileTileSource = new MultiMapFileTileSource();
//
// for (File mapFile : mapFileList) {
//
// if (!mapFile.exists() || !mapFile.getName().endsWith(".map")) {
// continue;
// }
//
// MapFileTileSource mTileSource = new MapFileTileSource();
//
// mTileSource.setPreferredLanguage("zh");
//
// if (mTileSource.setMapFile(mapFile.getAbsolutePath())) {
// multiMapFileTileSource.add(mTileSource);
// }
//
// }
//
// VectorTileLayer baseMapLayer = new OsmTileLayer(getVtmMap());
// baseMapLayer.setTileSource(multiMapFileTileSource);
//
// baseGroupLayer.layers.add(baseMapLayer);
//
// if (getTheme(null) != null)
// baseMapLayer.setTheme(getTheme(null));
//
// baseGroupLayer.layers.add(new BuildingLayer(getVtmMap(), baseMapLayer));
// baseGroupLayer.layers.add(new LabelLayer(getVtmMap(), baseMapLayer));
//
// for (Layer layer : baseGroupLayer.layers) {
// if (layer instanceof LabelLayer) {
// getVtmMap().layers().add(layer, LAYER_GROUPS.VECTOR.groupIndex);
// } else {
// getVtmMap().layers().add(layer, LAYER_GROUPS.BASE_VECTOR.groupIndex);
// }
// }
// }
// }
File baseMapFolder = new File(mapFilePath);
if (!baseMapFolder.exists()) {
return;
}
// //获取渲染资源
// public IRenderTheme getTheme(final String styleId) {
// AssetsRenderTheme theme = new AssetsRenderTheme(mContext.getAssets(), null, "default.xml");
// if (styleId == null || "".equals(styleId.trim())) {
// switch (2) {
// case 0:
// theme = new AssetsRenderTheme(mContext.getAssets(), null, "default.xml");
// break;
// case 1:
// theme = new AssetsRenderTheme(mContext.getAssets(), null, "osmarender.xml");
// break;
// case 2:
// theme = new AssetsRenderTheme(mContext.getAssets(), null, "tronrender.xml");
// break;
// }
//
// }
//
// return ThemeLoader.load(theme);
// }
File[] mapFileList = baseMapFolder.listFiles();
// public void addDefaultVectorTileLayer(MAP_THEME theme) {
// if (defaultVectorTileLayer != null) {
// getVtmMap().layers().remove(defaultVectorTileLayer);
// defaultVectorTileLayer = null;
// getVtmMap().updateMap();
// }
// defaultVectorTileLayer = mLayerManager.getDefaultVectorLayer(true);
// getVtmMap().layers().add(defaultVectorTileLayer, LAYER_GROUPS.VECTOR_TILE.groupIndex);
// defaultVectorLabelLayer = new LabelLayer(getVtmMap(), (VectorTileLayer) defaultVectorTileLayer);
// getVtmMap().layers().add(defaultVectorLabelLayer, LAYER_GROUPS.VECTOR_TILE.groupIndex);
// if (theme != null) {
//// switchTileVectorLayerTheme(theme);
// }
// getVtmMap().updateMap();
// }
if (mapFileList != null && mapFileList.length > 0) {
MultiMapFileTileSource multiMapFileTileSource = new MultiMapFileTileSource();
for (File mapFile : mapFileList) {
if (!mapFile.exists() || !mapFile.getName().endsWith(".map")) {
continue;
}
MapFileTileSource mTileSource = new MapFileTileSource();
mTileSource.setPreferredLanguage("zh");
if (mTileSource.setMapFile(mapFile.getAbsolutePath())) {
multiMapFileTileSource.add(mTileSource);
}
}
VectorTileLayer baseMapLayer = new OsmTileLayer(getVtmMap());
baseMapLayer.setTileSource(multiMapFileTileSource);
baseGroupLayer.layers.add(baseMapLayer);
if (getTheme(null) != null)
baseMapLayer.setTheme(getTheme(null));
baseGroupLayer.layers.add(new BuildingLayer(getVtmMap(), baseMapLayer));
baseGroupLayer.layers.add(new LabelLayer(getVtmMap(), baseMapLayer));
for (Layer layer : baseGroupLayer.layers) {
if (layer instanceof LabelLayer) {
getVtmMap().layers().add(layer, LAYER_GROUPS.VECTOR.groupIndex);
} else {
getVtmMap().layers().add(layer, LAYER_GROUPS.BASE_VECTOR.groupIndex);
}
}
}
}
//获取渲染资源
public IRenderTheme getTheme(final String styleId) {
AssetsRenderTheme theme = new AssetsRenderTheme(mContext.getAssets(), null, "default.xml");
if (styleId == null || "".equals(styleId.trim())) {
switch (2) {
case 0:
theme = new AssetsRenderTheme(mContext.getAssets(), null, "default.xml");
break;
case 1:
theme = new AssetsRenderTheme(mContext.getAssets(), null, "osmarender.xml");
break;
case 2:
theme = new AssetsRenderTheme(mContext.getAssets(), null, "tronrender.xml");
break;
}
}
return ThemeLoader.load(theme);
}
public void addDefaultVectorTileLayer(MAP_THEME theme) {
if (defaultVectorTileLayer != null) {
getVtmMap().layers().remove(defaultVectorTileLayer);
defaultVectorTileLayer = null;
getVtmMap().updateMap();
}
defaultVectorTileLayer = mLayerManager.getDefaultVectorLayer(true);
getVtmMap().layers().add(defaultVectorTileLayer, LAYER_GROUPS.VECTOR_TILE.groupIndex);
defaultVectorLabelLayer = new LabelLayer(getVtmMap(), (VectorTileLayer) defaultVectorTileLayer);
getVtmMap().layers().add(defaultVectorLabelLayer, LAYER_GROUPS.VECTOR_TILE.groupIndex);
if (theme != null) {
switchTileVectorLayerTheme(theme);
}
getVtmMap().updateMap();
}
public void setBaseRasterVisiable(boolean visiable) {
if (baseRasterLayer != null) {
baseRasterLayer.setEnabled(visiable);
getVtmMap().updateMap();
}
}
// public void setBaseRasterVisiable(boolean visiable) {
// if (baseRasterLayer != null) {
// baseRasterLayer.setEnabled(visiable);
// getVtmMap().updateMap();
// }
// }
/**
* 基础
@ -473,24 +566,26 @@ public final class NIMapView extends RelativeLayout {
}
}
/**
* 网格图层是否显示
*/
public void setGridLayerVisiable(boolean visiable) {
if (gridLayer != null) {
gridLayer.setEnabled(visiable);
getVtmMap().updateMap();
}
}
// /**
// * 网格图层是否显示
// */
// public void setGridLayerVisiable(boolean visiable) {
// if (gridLayer != null) {
// gridLayer.setEnabled(visiable);
// updateMap();
// }
// }
/**
* 图层组定义
*/
public enum LAYER_GROUPS {
BASE_RASTER(0)/*栅格底图*/, BASE_VECTOR(1)/*矢量底图*/,
RASTER_TILE(2)/*栅格网格*/, VECTOR_TILE(3)/*矢量网格*/,
VECTOR(4)/*矢量图层组*/, OTHER(5)/*其他图层*/,
ALLWAYS_SHOW_GROUP(6), OPERATE(7)/*操作图层组*/;
BASE(0)/*底图图层组*/,
VECTOR_TILE(1)/*矢量瓦片组*/,
VECTOR(2)/*高亮组*/,
OPERATE(3)/*操作图层组*/,
NAVIGATION(4)/*定位导航组*/;
int groupIndex;
LAYER_GROUPS(int groupIndex) {
@ -552,7 +647,7 @@ public final class NIMapView extends RelativeLayout {
* @param bundle
*/
public void onSaveInstanceState(Bundle bundle) {
super.onSaveInstanceState();
}
@ -560,11 +655,11 @@ public final class NIMapView extends RelativeLayout {
* 当Activity销毁时调用地图的销毁
*/
public void onDestroy() {
try{
try {
if (mapView != null) {
mapView.onDestroy();
}
}catch (Exception e){
} catch (Exception e) {
}
}
@ -627,9 +722,9 @@ public final class NIMapView extends RelativeLayout {
public void zoomIn(View view) {
if (view != null) {
if (view.isEnabled()) {
MapPosition mapPosition = mapView.map().getMapPosition();
MapPosition mapPosition = getVtmMap().getMapPosition();
mapPosition.setZoom(mapPosition.getZoom() + 1);
mapView.map().animator().animateTo(mapPosition);
getVtmMap().animator().animateTo(mapPosition);
// map.zoomIn(true);
}
view.setEnabled(false);
@ -648,9 +743,9 @@ public final class NIMapView extends RelativeLayout {
public void zoomOut(View view) {
if (view != null) {
if (view.isEnabled()) {
MapPosition mapPosition = mapView.map().getMapPosition();
MapPosition mapPosition = getVtmMap().getMapPosition();
mapPosition.setZoom(mapPosition.getZoom() - 1);
mapView.map().animator().animateTo(mapPosition);
getVtmMap().animator().animateTo(mapPosition);
// map.zoomOut(true);
}
@ -809,47 +904,9 @@ public final class NIMapView extends RelativeLayout {
}
}
public void switchTileVectorLayerTheme(MAP_THEME styleId) {
// 如果不包含vectorlayer则设置theme无效
boolean bHis = false;
for (Layer layer : getVtmMap().layers()) {
if (layer instanceof VectorTileLayer) {
bHis = true;
break;
}
}
if (!bHis) {
getVtmMap().updateMap(true);
return;
}
if (styleId == null) {
getVtmMap().setTheme(new AssetsRenderTheme(mContext.getAssets(), "", "navdefault.xml"), true);
} else {
switch (styleId) {
case NEWTRON:
getVtmMap().setTheme(VtmThemes.NEWTRON, true);
break;
case OSMAGRAY:
getVtmMap().setTheme(VtmThemes.OSMAGRAY, true);
break;
case OSMARENDER:
getVtmMap().setTheme(VtmThemes.OSMARENDER, true);
break;
case TRONRENDER:
getVtmMap().setTheme(VtmThemes.TRONRENDER, true);
break;
default:
getVtmMap().setTheme(new AssetsRenderTheme(mContext.getAssets(), "", "editormarker.xml"), true);
break;
}
}
getVtmMap().updateMap();
}
public NILayerManager getLayerManager() {
return mLayerManager;
}
// public NILayerManager getLayerManager() {
// return mLayerManager;
// }
// 地图点击事件对应的图层
private class MapEventsReceiver extends Layer implements GestureListener {
@ -874,7 +931,7 @@ public final class NIMapView extends RelativeLayout {
mapLongClickListener.onMapLongClick(geoPoint);
}
}
setOnMapClickListener(new NIMap.OnMapClickListener() {
setOnMapClickListener(new OnMapClickListener() {
@Override
public void onMapClick(GeoPoint point) {
@ -892,7 +949,7 @@ public final class NIMapView extends RelativeLayout {
/**
* 设置地图的点击事件
*/
public void setOnMapClickListener(@Nullable NIMap.OnMapClickListener listener) {
public void setOnMapClickListener(@Nullable OnMapClickListener listener) {
this.mapClickListener = listener;
}
@ -900,7 +957,7 @@ public final class NIMapView extends RelativeLayout {
* 设置地图的双击事件
* 默认情况下双击会自动放大地图
*/
public void setOnMapDoubleClickListener(@Nullable NIMap.OnMapDoubleClickListener listener) {
public void setOnMapDoubleClickListener(@Nullable OnMapDoubleClickListener listener) {
this.mapDoubleClickListener = listener;
}
@ -909,7 +966,7 @@ public final class NIMapView extends RelativeLayout {
*
* @param listener
*/
public void setOnMapLongClickListener(@Nullable NIMap.OnMapLongClickListener listener) {
public void setOnMapLongClickListener(@Nullable OnMapLongClickListener listener) {
this.mapLongClickListener = listener;
}
@ -918,7 +975,21 @@ public final class NIMapView extends RelativeLayout {
*
* @param listener
*/
public void setOnMapTouchListener(@Nullable NIMap.OnMapTouchListener listener) {
public void setOnMapTouchListener(@Nullable OnMapTouchListener listener) {
this.touchListener = listener;
}
/**
* 刷新地图
*/
public void updateMap() {
mapView.map().updateMap();
}
/**
* 刷新地图
*/
public void updateMap(boolean redraw) {
mapView.map().updateMap(redraw);
}
}

View File

@ -2,8 +2,21 @@ package com.navinfo.collect.library.map.handler
import android.content.Context
import com.navinfo.collect.library.map.NIMapView
import org.oscim.layers.Layer
open class BaseHandler(context:Context, mapView: NIMapView) {
protected val mContext:Context = context
abstract class BaseHandler(context: Context, mapView: NIMapView) {
protected val mContext: Context = context
protected val mMapView: NIMapView = mapView
fun addLayer(layer: Layer, groupType: NIMapView.LAYER_GROUPS) {
mMapView.vtmMap.layers().add(
layer,
groupType.groupIndex
)
}
fun removeLayer(layer: Layer) {
mMapView.vtmMap.layers().remove(layer)
}
}

View File

@ -1,35 +1,105 @@
package com.navinfo.collect.library.map.handler
import android.content.Context
import android.os.Environment
import com.navinfo.collect.library.map.NIMapView
import com.navinfo.collect.library.map.NIMapView.LAYER_GROUPS
import com.navinfo.collect.library.map.source.NavinfoMapRastorTileSource
import okhttp3.Cache
import okhttp3.OkHttpClient
import org.oscim.layers.Layer
import org.oscim.layers.LocationLayer
import org.oscim.layers.tile.bitmap.BitmapTileLayer
import org.oscim.tiling.source.OkHttpEngine.OkHttpFactory
import java.io.File
/**
* Layer 操作
*/
open class LayerManagerHandler(context: Context, mapView: NIMapView) :
class LayerManagerHandler(context: Context, mapView: NIMapView) :
BaseHandler(context, mapView) {
lateinit var mLocationLayer: LocationLayer
private var baseRasterLayer: Layer? = null
//增加RasterTileLayer
fun switchRasterTileLayer(
url: String?,
filePath: String? = "",
cache: Boolean? = false,
): Boolean {
mMapView.removeBaseMap()
val layer: Layer =
mMapView.layerManager.getRasterTileLayer(mContext, url, filePath, cache!!)
if (layer != null) {
mMapView.vtmMap.layers().add(layer, LAYER_GROUPS.BASE_RASTER.groupIndex)
mMapView.vtmMap.clearMap()
return true
init {
initMap()
}
/**
* 初始化地图
*/
private fun initMap() {
switchBaseMapType(BASE_MAP_TYPE.CYCLE_MAP)
// initVectorTileLayer()
// initMapLifeSource()
}
/**
* 切换基础底图样式
*/
fun switchBaseMapType(type: BASE_MAP_TYPE) {
if (baseRasterLayer != null) {
mMapView.vtmMap.layers().remove(baseRasterLayer)
baseRasterLayer = null
mMapView.vtmMap.updateMap()
}
return false
baseRasterLayer = getRasterTileLayer(type.url, type.tilePath, true)
addLayer(baseRasterLayer!!, LAYER_GROUPS.BASE)
mMapView.updateMap()
}
//删除RasterTileLayer
fun removeRasterTileLayer(url: String) {
private fun getRasterTileLayer(
url: String?,
tilePath: String?,
useCache: Boolean
): Layer {
val builder = OkHttpClient.Builder()
val mTileSource =
NavinfoMapRastorTileSource.builder(url).tilePath(tilePath)
.httpFactory(OkHttpFactory(builder)).build()
// 如果使用缓存
if (useCache) {
val cacheDirectory: File =
File(Environment.getExternalStorageState() + "/" + "lalalal", "tiles-raster")
val cacheSize = 300 * 1024 * 1024 // 300 MB
val cache = Cache(cacheDirectory, cacheSize.toLong())
builder.cache(cache)
}
// mTileSource.setHttpEngine(new OkHttpEngine.OkHttpFactory(builder));
// mTileSource.setHttpRequestHeaders(Collections.singletonMap("User-Agent", "vtm-android-example"));
// mTileSource.setCache(new TileCache(mContext, defaultDir, url.substring(url.indexOf(":")+1)));
return BitmapTileLayer(mMapView.vtmMap, mTileSource)
}
}
/**
* 基础
*/
enum class BASE_MAP_TYPE(// TransportMap底图
var title: String, var url: String, var tilePath: String
) {
OPEN_STREET_MAP(
"Open Street Map",
"http://a.tile.openstreetmap.org",
"/{Z}}/{X}/{Y}.png"
), // openStreetMap底图
CYCLE_MAP(
"Cycle Map",
"http://c.tile.opencyclemap.org/cycle",
"/{Z}}/{X}/{Y}.png"
), // cyclemap底图
S_MAP(
"SMap",
"http://smap.navinfo.com/gateway/smap-raster-map/raster/basemap/tile",
"z={Z}&x={X}&y={Y}"
), // cyclemap底图
TRANSPORT_MAP(
"Transport Map",
"http://b.tile2.opencyclemap.org/transport",
"/{Z}}/{X}/{Y}.png"
);
}

View File

@ -84,22 +84,10 @@ open class LineHandler(context: Context, mapView: NIMapView) :
.build()
mPathLayer = PathLayer(mMapView.vtmMap, lineStyle)
mMapView.layerManager.addLayer(
"defaultLineLayer",
mPathLayer,
NIMapView.LAYER_GROUPS.VECTOR.ordinal
)
// addLayer(mPathLayer, NIMapView.LAYER_GROUPS.OPERATE)
mPathLayerTemp = if (mMapView.layerManager.containsLayer("guideLineLayer")) {
mMapView.layerManager.getLayer("guideLineLayer") as PathLayer
} else {
PathLayer(mMapView.vtmMap, newTempStyle)
}
mMapView.layerManager.addLayer(
"guideLineLayer",
mPathLayerTemp,
NIMapView.LAYER_GROUPS.VECTOR.ordinal
)
mPathLayerTemp = PathLayer(mMapView.vtmMap, newTempStyle)
// addLayer(mPathLayerTemp, NIMapView.LAYER_GROUPS.OPERATE)
mPathMarkerBitmap = AndroidBitmap(
BitmapFactory.decodeResource(
@ -109,21 +97,10 @@ open class LineHandler(context: Context, mapView: NIMapView) :
)
val markerSymbol = MarkerSymbol(mPathMarkerBitmap, MarkerSymbol.HotspotPlace.CENTER)
//新增marker图层
mEndpointLayer = if (mMapView.layerManager.containsLayer("endpointLayer")) {
mMapView.layerManager.getLayer("endpointLayer") as ItemizedLayer
} else
//新增marker图层
ItemizedLayer(
mMapView.vtmMap,
java.util.ArrayList<MarkerInterface>(),
markerSymbol,
null
)
mMapView.layerManager.addLayer(
"endpointLayer",
mEndpointLayer,
NIMapView.LAYER_GROUPS.VECTOR.ordinal
mEndpointLayer = ItemizedLayer(
mMapView.vtmMap, ArrayList<MarkerInterface>(), markerSymbol, null
)
// addLayer(mEndpointLayer, NIMapView.LAYER_GROUPS.OPERATE)
mEndpointLayer.setOnItemGestureListener(object : OnItemGestureListener<MarkerInterface> {
override fun onItemSingleTapUp(index: Int, item: MarkerInterface): Boolean {
if (bDrawLine) {
@ -283,7 +260,7 @@ open class LineHandler(context: Context, mapView: NIMapView) :
}
fun addDrawLine(list: List<GeoPoint>) {
for(item in list){
for (item in list) {
addDrawLinePoint(item)
}
}

View File

@ -1,23 +1,129 @@
package com.navinfo.collect.library.map.handler
import android.content.Context
import com.navinfo.collect.library.map.NILocation
import android.util.Log
import android.widget.Toast
import com.baidu.location.BDAbstractLocationListener
import com.baidu.location.BDLocation
import com.baidu.location.LocationClient
import com.baidu.location.LocationClientOption
import com.baidu.location.LocationClientOption.LocationMode
import com.navinfo.collect.library.map.NIMapView
import org.oscim.layers.LocationLayer
open class LocationLayerHandler(context: Context, mapView:NIMapView) :
class LocationLayerHandler(context: Context, mapView: NIMapView) :
BaseHandler(context, mapView) {
private var mCurrentLocation: NILocation? = null
private var mCurrentLocation: BDLocation? = null
private val mLocationLayer: LocationLayer = LocationLayer(mMapView.vtmMap)
private lateinit var locationClient: LocationClient
init {
addLayer(mLocationLayer, NIMapView.LAYER_GROUPS.NAVIGATION)
initLocationOption()
}
/**
* 设置当前位置信息
* 初始化定位参数配置
*/
fun setCurrentLocation(location: NILocation) {
this.mCurrentLocation = location
mMapView.layerManager.locationLayer.setPosition(
location.latitude,
location.longitude,
location.radius
)
private fun initLocationOption() {
try {
LocationClient.setAgreePrivacy(true)
locationClient = LocationClient(mContext.applicationContext)
//定位服务的客户端。宿主程序在客户端声明此类,并调用,目前只支持在主线程中启动
//声明LocationClient类实例并配置定位参数
val locationOption = LocationClientOption()
val myLocationListener = MyLocationListener {
//此处的BDLocation为定位结果信息类通过它的各种get方法可获取定位相关的全部结果
//以下只列举部分获取经纬度相关(常用)的结果信息
//更多结果信息获取说明请参照类参考中BDLocation类中的说明
//获取纬度信息
val latitude = it.latitude
//获取经度信息
val longitude = it.longitude
//获取定位精度默认值为0.0f
val radius = it.radius
//获取经纬度坐标类型以LocationClientOption中设置过的坐标类型为准
val coorType = it.coorType
//获取定位类型、定位错误返回码具体信息可参照类参考中BDLocation类中的说明
val errorCode = it.locType
mCurrentLocation = it
mLocationLayer.setPosition(
it.latitude,
it.longitude,
it.radius
)
}
//注册监听函数
locationClient.registerLocationListener(myLocationListener)
//可选,默认高精度,设置定位模式,高精度,低功耗,仅设备
locationOption.locationMode = LocationMode.Hight_Accuracy
//可选默认gcj02设置返回的定位结果坐标系如果配合百度地图使用建议设置为bd09ll;
locationOption.setCoorType("gcj02")
//可选默认0即仅定位一次设置发起连续定位请求的间隔需要大于等于1000ms才是有效的
locationOption.setScanSpan(1000)
//可选,设置是否需要地址信息,默认不需要
locationOption.setIsNeedAddress(false)
//可选,设置是否需要地址描述
locationOption.setIsNeedLocationDescribe(false)
//可选,设置是否需要设备方向结果
locationOption.setNeedDeviceDirect(true)
//可选默认false设置是否当Gnss有效时按照1S1次频率输出Gnss结果
locationOption.isLocationNotify = true
//可选默认true定位SDK内部是一个SERVICE并放到了独立进程设置是否在stop的时候杀死这个进程默认不杀死
locationOption.setIgnoreKillProcess(true)
//可选默认false设置是否需要位置语义化结果可以在BDLocation.getLocationDescribe里得到结果类似于“在北京天安门附近”
locationOption.setIsNeedLocationDescribe(false)
//可选默认false设置是否需要POI结果可以在BDLocation.getPoiList里得到
locationOption.setIsNeedLocationPoiList(false)
//可选默认false设置是否收集CRASH信息默认收集
locationOption.SetIgnoreCacheException(false)
//可选默认false设置是否开启卫星定位
locationOption.isOpenGnss = true
//可选默认false设置定位时是否需要海拔信息默认不需要除基础定位版本都可用
locationOption.setIsNeedAltitude(true)
//设置打开自动回调位置模式该开关打开后期间只要定位SDK检测到位置变化就会主动回调给开发者该模式下开发者无需再关心定位间隔是多少定位SDK本身发现位置变化就会及时回调给开发者
// locationOption.setOpenAutoNotifyMode()
//设置打开自动回调位置模式该开关打开后期间只要定位SDK检测到位置变化就会主动回调给开发者
locationOption.setOpenAutoNotifyMode(
1000,
1,
LocationClientOption.LOC_SENSITIVITY_HIGHT
)
//需将配置好的LocationClientOption对象通过setLocOption方法传递给LocationClient对象使用
locationClient.locOption = locationOption
} catch (e: Throwable) {
Toast.makeText(mContext, "定位初始化失败 $e", Toast.LENGTH_SHORT)
}
}
fun startLocation() {
//开始定位
if (!locationClient.isStarted) {
locationClient.start()
}
}
fun stopLocation() {
if (locationClient.isStarted) {
locationClient.stop()
}
}
}
/**
* 实现定位回调
*/
private class MyLocationListener(callback: (BDLocation) -> Unit) :
BDAbstractLocationListener() {
val call = callback;
override fun onReceiveLocation(location: BDLocation) {
call(location)
}
}

View File

@ -1,18 +0,0 @@
package com.navinfo.collect.library.map.handler
import android.content.Context
import com.navinfo.collect.library.map.NIMapView
open class MapBaseControlHandler(context: Context, mapView: NIMapView) :
BaseHandler(context, mapView) {
/**
* 刷新地图
*/
fun upDateMap(redraw: Boolean = true) {
if (redraw) {
mMapView.vtmMap.events.fire(org.oscim.map.Map.CLEAR_EVENT, mMapView.vtmMap.mapPosition)
}
mMapView.vtmMap.updateMap(redraw)
}
}

View File

@ -14,56 +14,56 @@ import org.oscim.layers.marker.MarkerItem
open class MarkHandler(context: Context, mapView:NIMapView) :
BaseHandler(context, mapView), OnItemGestureListener<MarkerInterface> {
//增加marker
fun addMarker(
geoPoint: GeoPoint,
title: String?,
description: String? = ""
): MarkerItem {
var marker: MarkerItem? = null
for (e in mMapView.layerManager.defaultMarkerLayer.itemList) {
if (e is MarkerItem && e.title == title) {
marker = e;
break;
}
}
if (marker == null) {
var tempTitle = title;
if (tempTitle.isNullOrBlank()) {
tempTitle = StringUtil.createUUID();
}
val marker = MarkerItem(
tempTitle,
description,
geoPoint
)
mMapView.layerManager.defaultMarkerLayer.addItem(marker);
mMapView.vtmMap.updateMap(true)
return marker
} else {
marker.description = description
marker.geoPoint = geoPoint
mMapView.layerManager.defaultMarkerLayer.removeItem(marker)
mMapView.layerManager.defaultMarkerLayer.addItem(marker)
mMapView.vtmMap.updateMap(true)
return marker
}
}
fun removeMarker(title: String) {
var marker: MarkerItem? = null
for (e in mMapView.layerManager.defaultMarkerLayer.itemList) {
if (e is MarkerItem && e.title == title) {
marker = e;
break;
}
}
if (marker != null) {
mMapView.layerManager.defaultMarkerLayer.removeItem(marker)
mMapView.vtmMap.updateMap(true)
}
}
// //增加marker
// fun addMarker(
// geoPoint: GeoPoint,
// title: String?,
// description: String? = ""
// ): MarkerItem {
// var marker: MarkerItem? = null
// for (e in mMapView.layerManager.defaultMarkerLayer.itemList) {
// if (e is MarkerItem && e.title == title) {
// marker = e;
// break;
// }
// }
// if (marker == null) {
// var tempTitle = title;
// if (tempTitle.isNullOrBlank()) {
// tempTitle = StringUtil.createUUID();
// }
// val marker = MarkerItem(
// tempTitle,
// description,
// geoPoint
// )
// mMapView.layerManager.defaultMarkerLayer.addItem(marker);
// mMapView.vtmMap.updateMap(true)
// return marker
// } else {
// marker.description = description
// marker.geoPoint = geoPoint
// mMapView.layerManager.defaultMarkerLayer.removeItem(marker)
// mMapView.layerManager.defaultMarkerLayer.addItem(marker)
// mMapView.vtmMap.updateMap(true)
// return marker
// }
// }
//
// fun removeMarker(title: String) {
// var marker: MarkerItem? = null
// for (e in mMapView.layerManager.defaultMarkerLayer.itemList) {
// if (e is MarkerItem && e.title == title) {
// marker = e;
// break;
// }
// }
// if (marker != null) {
// mMapView.layerManager.defaultMarkerLayer.removeItem(marker)
// mMapView.vtmMap.updateMap(true)
// }
// }
//
override fun onItemSingleTapUp(index: Int, item: MarkerInterface): Boolean {
return false
}

View File

@ -7,7 +7,6 @@ import android.graphics.Color
import android.text.TextPaint
import android.widget.Toast
import com.navinfo.collect.library.R
import com.navinfo.collect.library.map.NILayerManager
import com.navinfo.collect.library.map.NIMapView
import com.navinfo.collect.library.map.handler.BaseHandler
import com.navinfo.collect.library.map.layers.NIPolygonLayer
@ -39,6 +38,7 @@ open class MeasureLayerHandler(context: Context, mapView: NIMapView) :
private val bDrawPoint = false
private var mAreaLayer: ItemizedLayer
//绘制线 样式
private val lineStyle: Style
@ -49,8 +49,10 @@ open class MeasureLayerHandler(context: Context, mapView: NIMapView) :
//新增线数据引线
private var mPathLayerTemp: PathLayer
//新增线数据
private var mPathLayer: PathLayer
//线路端点图标
private var mPathMarkerBitmap: Bitmap
@ -67,7 +69,7 @@ open class MeasureLayerHandler(context: Context, mapView: NIMapView) :
.fillColor(context.resources.getColor(R.color.draw_line_blue2_color, null))
.fillAlpha(0.5f)
.strokeColor(context.resources.getColor(R.color.draw_line_blue2_color, null))
.fillColor(context.resources.getColor(R.color.draw_line_red_color,null))
.fillColor(context.resources.getColor(R.color.draw_line_red_color, null))
.stippleWidth(4f)
.fixed(true)
.build()
@ -96,22 +98,10 @@ open class MeasureLayerHandler(context: Context, mapView: NIMapView) :
mMapView.vtmMap,
lineStyle
)
mMapView.layerManager.addLayer(
"meatureLayer",
mPolygonLayer,
NIMapView.LAYER_GROUPS.VECTOR.ordinal
)
// addLayer(mPolygonLayer, NIMapView.LAYER_GROUPS.OPERATE)
mPathLayerTemp = if (mMapView.layerManager.containsLayer("meatureLineLayer")) {
mMapView.layerManager.getLayer("meatureLineLayer") as PathLayer
} else {
PathLayer(mMapView.vtmMap, newTempStyle)
}
mMapView.layerManager.addLayer(
"meatureLineLayer",
mPathLayerTemp,
NIMapView.LAYER_GROUPS.VECTOR.ordinal
)
mPathLayerTemp = PathLayer(mMapView.vtmMap, newTempStyle)
// addLayer(mPathLayerTemp, NIMapView.LAYER_GROUPS.OPERATE)
mPathMarkerBitmap = AndroidBitmap(
BitmapFactory.decodeResource(
@ -126,175 +116,181 @@ open class MeasureLayerHandler(context: Context, mapView: NIMapView) :
mPathLayer = PathLayer(mMapView.vtmMap, lineStyle)
mMapView.vtmMap.layers().add(mPathLayer, NIMapView.LAYER_GROUPS.OTHER.ordinal)
addLayer(mPathLayer, NIMapView.LAYER_GROUPS.OPERATE)
}
open fun drawLineOrPolygon(type: Int) {
bDrawLine = true
//画面
if (type == 3) {
if (mPolygonLayer == null) {
mPolygonLayer = NIPolygonLayer(mMapView.vtmMap, lineStyle)
mMapView.vtmMap.layers().add(mPolygonLayer, NIMapView.LAYER_GROUPS.OTHER.ordinal)
} else if (!mPolygonLayer.isEnabled) {
mPolygonLayer.isEnabled = true
}
} else {
if (mPathLayer == null) {
mPathLayer = PathLayer(mMapView.vtmMap, lineStyle)
mMapView.vtmMap.layers().add(mPathLayer, NIMapView.LAYER_GROUPS.OTHER.ordinal)
} else if (!mPathLayer.isEnabled()) {
mPathLayer.setEnabled(true)
}
}
//上一个点的引线
if (mPathLayerTemp == null) {
mPathLayerTemp = PathLayer(mMapView.vtmMap, newTempStyle)
mMapView.vtmMap.layers().add(mPathLayerTemp, NIMapView.LAYER_GROUPS.OTHER.ordinal)
} else if (!mPathLayerTemp.isEnabled) {
mPathLayerTemp.isEnabled = true
}
val geoPoint: GeoPoint =
GeoPoint(mMapView.vtmMap.getMapPosition().getLatitude(), mMapView.vtmMap.getMapPosition().getLongitude())
//编辑点
if (editIndex > -1) {
if (mPathMakers.size > editIndex) {
mMapView.layerManager.removeMarker(mPathMakers[editIndex], NILayerManager.MARQUEE_MARKER_LAYER)
mPathMakers.removeAt(editIndex)
if (mPathMarkerBitmap == null) {
mPathMarkerBitmap = AndroidBitmap(
BitmapFactory.decodeResource(
mContext.getResources(),
R.mipmap.icon_path_maker
)
)
}
val markerItem = MarkerItem(createUUID(), "", "", geoPoint)
val markerSymbol = MarkerSymbol(mPathMarkerBitmap, MarkerSymbol.HotspotPlace.CENTER)
markerItem.marker = markerSymbol
mMapView.layerManager.addMarker2MarkerLayer(
markerItem,
mPathMarkerBitmap,
NILayerManager.MARQUEE_MARKER_LAYER,
NIMapView.LAYER_GROUPS.OTHER.ordinal,
itemGestureListener
)
mPathMakers.add(editIndex, markerItem)
if (mPathLayer != null && mPathLayer.getPoints().size > 0) {
val list: MutableList<GeoPoint> = mPathLayer.getPoints()
if (editIndex < list.size) {
list.removeAt(editIndex)
val list2: MutableList<GeoPoint> = java.util.ArrayList(list)
list2.add(editIndex, geoPoint)
mPathLayer.setPoints(list2)
}
} else if (mPolygonLayer != null && mPolygonLayer.points.size > 0) {
val list = mPolygonLayer.points
if (editIndex < list.size) {
list.removeAt(editIndex)
val list2: MutableList<GeoPoint> = java.util.ArrayList(list)
list2.add(editIndex, geoPoint)
mPolygonLayer.setPoints(list2)
}
}
if (mPathLayerTemp != null) {
mPathLayerTemp.setStyle(newTempStyle)
val list: MutableList<GeoPoint> = java.util.ArrayList<GeoPoint>()
if (type == 3 && mPathMakers.size > 1) {
list.add(mPathMakers[0].geoPoint)
list.add(geoPoint)
list.add(mPathMakers[mPathMakers.size - 1].geoPoint)
} else {
list.add(mPathMakers[mPathMakers.size - 1].geoPoint)
list.add(geoPoint)
}
mPathLayerTemp.setPoints(list)
}
}
editIndex = -1
} else { //新增点
if (type == 3) {
val points: MutableList<GeoPoint> = java.util.ArrayList(mPolygonLayer.points)
if (points.size > 2) {
val list: MutableList<GeoPoint> = java.util.ArrayList()
points.add(points[0])
list.add(points[0])
list.add(geoPoint)
list.add(mPolygonLayer.points[mPolygonLayer.points.size - 1])
val bCross = GeometryTools.isPolygonCrosses(points, list)
if (bCross == true) {
Toast.makeText(mContext, "不能交叉", Toast.LENGTH_SHORT).show()
return
}
}
mPolygonLayer.addPoint(geoPoint)
} else {
val points: List<GeoPoint> = mPathLayer.getPoints()
if (points.size > 2) {
val list: MutableList<GeoPoint> = java.util.ArrayList()
list.add(geoPoint)
list.add(points[points.size - 1])
val bCross = GeometryTools.isLineStringCrosses(points, list)
if (bCross == true) {
Toast.makeText(mContext, "不能交叉", Toast.LENGTH_SHORT).show()
return
}
}
mPathLayer.addPoint(geoPoint)
}
if (mPathMarkerBitmap == null) {
mPathMarkerBitmap = AndroidBitmap(
BitmapFactory.decodeResource(
mContext.getResources(),
R.mipmap.icon_path_maker
)
)
}
val markerItem = MarkerItem(createUUID(), "", "", geoPoint)
val markerSymbol = MarkerSymbol(mPathMarkerBitmap, MarkerSymbol.HotspotPlace.CENTER)
markerItem.marker = markerSymbol
mMapView.layerManager.addMarker2MarkerLayer(
markerItem,
mPathMarkerBitmap,
NILayerManager.MARQUEE_MARKER_LAYER,
NIMapView.LAYER_GROUPS.OTHER.ordinal,
itemGestureListener
)
mPathMakers.add(markerItem)
}
// //画面
// if (type == 3) {
// if (mPolygonLayer == null) {
// mPolygonLayer = NIPolygonLayer(mMapView.vtmMap, lineStyle)
// addLayer(mPolygonLayer, NIMapView.LAYER_GROUPS.OPERATE)
// } else if (!mPolygonLayer.isEnabled) {
// mPolygonLayer.isEnabled = true
// }
// } else {
// if (mPathLayer == null) {
// mPathLayer = PathLayer(mMapView.vtmMap, lineStyle)
// addLayer(mPathLayer, NIMapView.LAYER_GROUPS.OPERATE)
// } else if (!mPathLayer.isEnabled()) {
// mPathLayer.setEnabled(true)
// }
// }
// //上一个点的引线
// if (mPathLayerTemp == null) {
// mPathLayerTemp = PathLayer(mMapView.vtmMap, newTempStyle)
// addLayer(mPathLayerTemp, NIMapView.LAYER_GROUPS.OPERATE)
// } else if (!mPathLayerTemp.isEnabled) {
// mPathLayerTemp.isEnabled = true
// }
// val geoPoint: GeoPoint =
// GeoPoint(
// mMapView.vtmMap.getMapPosition().getLatitude(),
// mMapView.vtmMap.getMapPosition().getLongitude()
// )
//
// //编辑点
// if (editIndex > -1) {
// if (mPathMakers.size > editIndex) {
// mMapView.layerManager.removeMarker(
// mPathMakers[editIndex],
// NILayerManager.MARQUEE_MARKER_LAYER
// )
// mPathMakers.removeAt(editIndex)
// if (mPathMarkerBitmap == null) {
// mPathMarkerBitmap = AndroidBitmap(
// BitmapFactory.decodeResource(
// mContext.getResources(),
// R.mipmap.icon_path_maker
// )
// )
// }
// val markerItem = MarkerItem(createUUID(), "", "", geoPoint)
// val markerSymbol = MarkerSymbol(mPathMarkerBitmap, MarkerSymbol.HotspotPlace.CENTER)
// markerItem.marker = markerSymbol
// mMapView.layerManager.addMarker2MarkerLayer(
// markerItem,
// mPathMarkerBitmap,
// NILayerManager.MARQUEE_MARKER_LAYER,
// NIMapView.LAYER_GROUPS.OTHER.ordinal,
// itemGestureListener
// )
// mPathMakers.add(editIndex, markerItem)
// if (mPathLayer != null && mPathLayer.getPoints().size > 0) {
// val list: MutableList<GeoPoint> = mPathLayer.getPoints()
// if (editIndex < list.size) {
// list.removeAt(editIndex)
// val list2: MutableList<GeoPoint> = java.util.ArrayList(list)
// list2.add(editIndex, geoPoint)
// mPathLayer.setPoints(list2)
// }
// } else if (mPolygonLayer != null && mPolygonLayer.points.size > 0) {
// val list = mPolygonLayer.points
// if (editIndex < list.size) {
// list.removeAt(editIndex)
// val list2: MutableList<GeoPoint> = java.util.ArrayList(list)
// list2.add(editIndex, geoPoint)
// mPolygonLayer.setPoints(list2)
// }
// }
// if (mPathLayerTemp != null) {
// mPathLayerTemp.setStyle(newTempStyle)
// val list: MutableList<GeoPoint> = java.util.ArrayList<GeoPoint>()
// if (type == 3 && mPathMakers.size > 1) {
// list.add(mPathMakers[0].geoPoint)
// list.add(geoPoint)
// list.add(mPathMakers[mPathMakers.size - 1].geoPoint)
// } else {
// list.add(mPathMakers[mPathMakers.size - 1].geoPoint)
// list.add(geoPoint)
// }
// mPathLayerTemp.setPoints(list)
// }
// }
// editIndex = -1
// } else { //新增点
// if (type == 3) {
// val points: MutableList<GeoPoint> = java.util.ArrayList(mPolygonLayer.points)
// if (points.size > 2) {
// val list: MutableList<GeoPoint> = java.util.ArrayList()
// points.add(points[0])
// list.add(points[0])
// list.add(geoPoint)
// list.add(mPolygonLayer.points[mPolygonLayer.points.size - 1])
// val bCross = GeometryTools.isPolygonCrosses(points, list)
// if (bCross == true) {
// Toast.makeText(mContext, "不能交叉", Toast.LENGTH_SHORT).show()
// return
// }
// }
// mPolygonLayer.addPoint(geoPoint)
// } else {
// val points: List<GeoPoint> = mPathLayer.getPoints()
// if (points.size > 2) {
// val list: MutableList<GeoPoint> = java.util.ArrayList()
// list.add(geoPoint)
// list.add(points[points.size - 1])
// val bCross = GeometryTools.isLineStringCrosses(points, list)
// if (bCross == true) {
// Toast.makeText(mContext, "不能交叉", Toast.LENGTH_SHORT).show()
// return
// }
// }
// mPathLayer.addPoint(geoPoint)
// }
// if (mPathMarkerBitmap == null) {
// mPathMarkerBitmap = AndroidBitmap(
// BitmapFactory.decodeResource(
// mContext.getResources(),
// R.mipmap.icon_path_maker
// )
// )
// }
// val markerItem = MarkerItem(createUUID(), "", "", geoPoint)
// val markerSymbol = MarkerSymbol(mPathMarkerBitmap, MarkerSymbol.HotspotPlace.CENTER)
// markerItem.marker = markerSymbol
// mMapView.layerManager.addMarker2MarkerLayer(
// markerItem,
// mPathMarkerBitmap,
// NILayerManager.MARQUEE_MARKER_LAYER,
// NIMapView.LAYER_GROUPS.OTHER.ordinal,
// itemGestureListener
// )
// mPathMakers.add(markerItem)
// }
showAreaLayer()
}
open fun drawLineBackspace() {
if (mPathLayer != null && mPathLayer.getPoints().size > 0) {
val list: MutableList<GeoPoint> = java.util.ArrayList<GeoPoint>(mPathLayer.getPoints())
val point = list[mPathLayer.getPoints().size - 1]
list.remove(point)
mPathLayer.setPoints(list)
mMapView.layerManager.jumpToPosition(point.longitude, point.latitude, 0)
} else if (mPolygonLayer != null && mPolygonLayer.points.size > 0) {
val list: MutableList<GeoPoint> = java.util.ArrayList<GeoPoint>(mPolygonLayer.points)
val point = list[mPolygonLayer.points.size - 1]
list.remove(point)
mPolygonLayer.setPoints(list)
mMapView.layerManager.jumpToPosition(point!!.longitude, point.latitude, 0)
}
if (mPathMakers.size > 0) {
var item: MarkerItem? = mPathMakers[mPathMakers.size - 1]
mMapView.layerManager.removeMarker(item, NILayerManager.MARQUEE_MARKER_LAYER)
mPathMakers.remove(item)
item = null
}
if (mPathMakers.size == 0 && mPathLayerTemp != null) {
mPathLayerTemp.clearPath()
}
editIndex = -1
if (mPathLayerTemp != null) {
mPathLayerTemp.setStyle(newTempStyle)
}
// if (mPathLayer != null && mPathLayer.getPoints().size > 0) {
// val list: MutableList<GeoPoint> = java.util.ArrayList<GeoPoint>(mPathLayer.getPoints())
// val point = list[mPathLayer.getPoints().size - 1]
// list.remove(point)
// mPathLayer.setPoints(list)
// mMapView.layerManager.jumpToPosition(point.longitude, point.latitude, 0)
// } else if (mPolygonLayer != null && mPolygonLayer.points.size > 0) {
// val list: MutableList<GeoPoint> = java.util.ArrayList<GeoPoint>(mPolygonLayer.points)
// val point = list[mPolygonLayer.points.size - 1]
// list.remove(point)
// mPolygonLayer.setPoints(list)
// mMapView.layerManager.jumpToPosition(point!!.longitude, point.latitude, 0)
// }
// if (mPathMakers.size > 0) {
// var item: MarkerItem? = mPathMakers[mPathMakers.size - 1]
// mMapView.layerManager.removeMarker(item, NILayerManager.MARQUEE_MARKER_LAYER)
// mPathMakers.remove(item)
// item = null
// }
// if (mPathMakers.size == 0 && mPathLayerTemp != null) {
// mPathLayerTemp.clearPath()
// }
// editIndex = -1
// if (mPathLayerTemp != null) {
// mPathLayerTemp.setStyle(newTempStyle)
// }
}
@ -322,8 +318,8 @@ open class MeasureLayerHandler(context: Context, mapView: NIMapView) :
val area = DistanceUtil.planarPolygonAreaMeters2(list)
var areaString: String
if (area < 1000000) {
areaString = area.toString()+"平方米"
} else if (area < 10000000000.0){
areaString = area.toString() + "平方米"
} else if (area < 10000000000.0) {
val d = area / 1000000.0
val bg = BigDecimal(d)
val f1 = bg.setScale(1, BigDecimal.ROUND_HALF_UP).toDouble()
@ -364,25 +360,25 @@ open class MeasureLayerHandler(context: Context, mapView: NIMapView) :
}
open fun removeLine() {
bDrawLine = false
editIndex = -1
for (item in mPathMakers) {
mMapView.layerManager.removeMarker(item, NILayerManager.MARQUEE_MARKER_LAYER)
}
mPathMakers.clear()
if (mPathLayer != null) {
mPathLayer.clearPath()
mPathLayer.isEnabled = false
}
if (mPolygonLayer != null) {
mPolygonLayer.clearPath()
mPolygonLayer.isEnabled = false
}
if (mPathLayerTemp != null) {
mPathLayerTemp.clearPath()
mPathLayerTemp.isEnabled = false
mPathLayerTemp.setStyle(newTempStyle)
}
// bDrawLine = false
// editIndex = -1
// for (item in mPathMakers) {
// mMapView.layerManager.removeMarker(item, NILayerManager.MARQUEE_MARKER_LAYER)
// }
// mPathMakers.clear()
// if (mPathLayer != null) {
// mPathLayer.clearPath()
// mPathLayer.isEnabled = false
// }
// if (mPolygonLayer != null) {
// mPolygonLayer.clearPath()
// mPolygonLayer.isEnabled = false
// }
// if (mPathLayerTemp != null) {
// mPathLayerTemp.clearPath()
// mPathLayerTemp.isEnabled = false
// mPathLayerTemp.setStyle(newTempStyle)
// }
hideAreaLayer()
}
@ -399,27 +395,31 @@ open class MeasureLayerHandler(context: Context, mapView: NIMapView) :
object : OnItemGestureListener<MarkerInterface> {
override fun onItemSingleTapUp(index: Int, item: MarkerInterface): Boolean {
if (bDrawLine) {
for (i in mPathMakers.indices) {
val item1 = mPathMakers[i]
if (item === item1) {
mMapView.layerManager.jumpToPosition(item.getPoint().longitude, item.getPoint().latitude, 0)
editIndex = i
if (mPathLayerTemp != null) {
mPathLayerTemp.setStyle(editTempStyle)
val list: MutableList<GeoPoint> = java.util.ArrayList<GeoPoint>()
if (editIndex == 0 || editIndex == mPathMakers.size - 1) {
list.add(item.geoPoint as Nothing)
list.add(item.geoPoint as Nothing)
} else {
list.add(mPathMakers[editIndex - 1].geoPoint as Nothing)
list.add(item.geoPoint as Nothing)
list.add(mPathMakers[editIndex + 1].geoPoint as Nothing)
}
mPathLayerTemp.setPoints(list)
}
return true
}
}
// for (i in mPathMakers.indices) {
// val item1 = mPathMakers[i]
// if (item === item1) {
// mMapView.layerManager.jumpToPosition(
// item.getPoint().longitude,
// item.getPoint().latitude,
// 0
// )
// editIndex = i
// if (mPathLayerTemp != null) {
// mPathLayerTemp.setStyle(editTempStyle)
// val list: MutableList<GeoPoint> = java.util.ArrayList<GeoPoint>()
// if (editIndex == 0 || editIndex == mPathMakers.size - 1) {
// list.add(item.geoPoint as Nothing)
// list.add(item.geoPoint as Nothing)
// } else {
// list.add(mPathMakers[editIndex - 1].geoPoint as Nothing)
// list.add(item.geoPoint as Nothing)
// list.add(mPathMakers[editIndex + 1].geoPoint as Nothing)
// }
// mPathLayerTemp.setPoints(list)
// }
// return true
// }
// }
}
return false
}

View File

@ -5,12 +5,10 @@ import android.graphics.BitmapFactory
import android.util.Log
import android.widget.Toast
import com.navinfo.collect.library.R
import com.navinfo.collect.library.map.NILayerManager
import com.navinfo.collect.library.map.NIMapView
import com.navinfo.collect.library.map.layers.NIPolygonLayer
import com.navinfo.collect.library.utils.GeometryTools
import com.navinfo.collect.library.utils.StringUtil
import com.navinfo.collect.library.utils.StringUtil.Companion.createUUID
import org.oscim.android.canvas.AndroidBitmap
import org.oscim.backend.canvas.Bitmap
import org.oscim.core.GeoPoint
@ -41,13 +39,13 @@ open class PolygonHandler(context: Context, mapView: NIMapView) :
private val editTempStyle: Style
//新增线数据引线
private var mPathLayerTemp: PathLayer
private lateinit var mPathLayerTemp: PathLayer
//线路端点图标
private var mPathMarkerBitmap: Bitmap
//线路端点marker
private val mEndpointLayer: ItemizedLayer
private lateinit var mEndpointLayer: ItemizedLayer
private var bDrawPolygon = false
@ -92,22 +90,22 @@ open class PolygonHandler(context: Context, mapView: NIMapView) :
mMapView.vtmMap,
lineStyle
)
mMapView.layerManager.addLayer(
"defaultPolygonLayer",
mPolygonLayer,
NIMapView.LAYER_GROUPS.VECTOR.ordinal
)
mPathLayerTemp = if (mMapView.layerManager.containsLayer("guideLineLayer")) {
mMapView.layerManager.getLayer("guideLineLayer") as PathLayer
} else {
PathLayer(mMapView.vtmMap, newTempStyle)
}
mMapView.layerManager.addLayer(
"guideLineLayer",
mPathLayerTemp,
NIMapView.LAYER_GROUPS.VECTOR.ordinal
)
// mMapView.layerManager.addLayer(
// "defaultPolygonLayer",
// mPolygonLayer,
// NIMapView.LAYER_GROUPS.VECTOR.ordinal
// )
//
// mPathLayerTemp = if (mMapView.layerManager.containsLayer("guideLineLayer")) {
// mMapView.layerManager.getLayer("guideLineLayer") as PathLayer
// } else {
// PathLayer(mMapView.vtmMap, newTempStyle)
// }
// mMapView.layerManager.addLayer(
// "guideLineLayer",
// mPathLayerTemp,
// NIMapView.LAYER_GROUPS.VECTOR.ordinal
// )
mPathMarkerBitmap = AndroidBitmap(
BitmapFactory.decodeResource(
@ -118,57 +116,57 @@ open class PolygonHandler(context: Context, mapView: NIMapView) :
val markerSymbol = MarkerSymbol(mPathMarkerBitmap, MarkerSymbol.HotspotPlace.CENTER)
mEndpointLayer = if (mMapView.layerManager.containsLayer("endpointLayer")) {
mMapView.layerManager.getLayer("endpointLayer") as ItemizedLayer
} else
//新增marker图层
ItemizedLayer(
mMapView.vtmMap,
java.util.ArrayList<MarkerInterface>(),
markerSymbol,
null
)
mMapView.layerManager.addLayer(
"endpointLayer",
mEndpointLayer,
NIMapView.LAYER_GROUPS.VECTOR.ordinal
)
// mEndpointLayer = if (mMapView.layerManager.containsLayer("endpointLayer")) {
// mMapView.layerManager.getLayer("endpointLayer") as ItemizedLayer
// } else
// //新增marker图层
// ItemizedLayer(
// mMapView.vtmMap,
// java.util.ArrayList<MarkerInterface>(),
// markerSymbol,
// null
// )
// mMapView.layerManager.addLayer(
// "endpointLayer",
// mEndpointLayer,
// NIMapView.LAYER_GROUPS.VECTOR.ordinal
// )
mEndpointLayer.setOnItemGestureListener(object : OnItemGestureListener<MarkerInterface> {
override fun onItemSingleTapUp(index: Int, item: MarkerInterface): Boolean {
if (bDrawPolygon) {
for (i in mPathMakers.indices) {
val item1 = mPathMakers[i]
if (item === item1) {
mMapView.vtmMap.animator().animateTo(
GeoPoint(
item.getPoint().latitude,
item.getPoint().longitude
)
)
editIndex = i
mPathLayerTemp.setStyle(editTempStyle)
val list: MutableList<GeoPoint> = mutableListOf()
if (editIndex == 0 || editIndex == mPathMakers.size - 1) {
list.add(item.getPoint())
list.add(item.getPoint())
} else {
list.add(mPathMakers[editIndex - 1].geoPoint)
list.add(item.getPoint())
list.add(mPathMakers[editIndex + 1].geoPoint)
}
mPathLayerTemp.setPoints(list)
return false
}
}
}
return false
}
override fun onItemLongPress(index: Int, item: MarkerInterface): Boolean {
return false
}
})
// mEndpointLayer.setOnItemGestureListener(object : OnItemGestureListener<MarkerInterface> {
// override fun onItemSingleTapUp(index: Int, item: MarkerInterface): Boolean {
// if (bDrawPolygon) {
// for (i in mPathMakers.indices) {
// val item1 = mPathMakers[i]
// if (item === item1) {
// mMapView.vtmMap.animator().animateTo(
// GeoPoint(
// item.getPoint().latitude,
// item.getPoint().longitude
// )
// )
// editIndex = i
// mPathLayerTemp.setStyle(editTempStyle)
// val list: MutableList<GeoPoint> = mutableListOf()
// if (editIndex == 0 || editIndex == mPathMakers.size - 1) {
// list.add(item.getPoint())
// list.add(item.getPoint())
// } else {
// list.add(mPathMakers[editIndex - 1].geoPoint)
// list.add(item.getPoint())
// list.add(mPathMakers[editIndex + 1].geoPoint)
// }
// mPathLayerTemp.setPoints(list)
// return false
// }
// }
// }
// return false
// }
//
// override fun onItemLongPress(index: Int, item: MarkerInterface): Boolean {
// return false
// }
// })
}
fun addDrawPolygonPoint(geoPoint: GeoPoint): List<GeoPoint> {

View File

@ -61,7 +61,7 @@ public class NaviLocationLayer extends LocationTextureLayer {
this.locationRenderer.setColor(0xffa1dbf5);
this.locationRenderer.setShowAccuracyZoom(4);
this.setEnabled(true); // 默认开启当前位置显示
mMap.layers().add(this, NIMapView.LAYER_GROUPS.ALLWAYS_SHOW_GROUP.getGroupIndex());
mMap.layers().add(this, NIMapView.LAYER_GROUPS.NAVIGATION.getGroupIndex());
return this;
}
}

View File

@ -73,7 +73,7 @@ public class NaviMapScaleBar extends MapScaleBar {
BitmapRenderer renderer = mapScaleBarLayer.getRenderer();
renderer.setPosition(position); // 设置scaleBar在地图上的位置
renderer.setOffset(xOffset * CanvasAdapter.getScale(), yOffset* CanvasAdapter.getScale());
this.map.layers().add(mapScaleBarLayer, NIMapView.LAYER_GROUPS.ALLWAYS_SHOW_GROUP.ordinal());
this.map.layers().add(mapScaleBarLayer, NIMapView.LAYER_GROUPS.NAVIGATION.ordinal());
return mapScaleBarLayer;
}

View File

@ -1,5 +1,7 @@
package com.navinfo.collect.library.map.source;
import android.util.Log;
import org.oscim.backend.CanvasAdapter;
import org.oscim.backend.canvas.Bitmap;
import org.oscim.core.Tile;
@ -32,6 +34,7 @@ public class NavinfoMapRastorTileSource extends UrlTileSource {
public static class Builder<T extends Builder<T>> extends UrlTileSource.Builder<T> {
private boolean isTMSProtocol = true;
public Builder(String url) {
super(url, DEFAULT_PATH);
overZoom(2);

View File

@ -1,64 +1,70 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
android:layout_width="match_parent"
android:layout_height="match_parent">
<org.oscim.android.MapView
android:id="@+id/base_map_view"
android:layout_width="match_parent"
android:layout_height="match_parent"></org.oscim.android.MapView>
android:layout_height="match_parent" />
<ImageView
android:id="@+id/navinfo_map_compass"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="@dimen/nimap_defalut_padding"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_marginTop="50dp"
android:src="@mipmap/compass"></ImageView>
android:padding="@dimen/nimap_defalut_padding"
android:src="@mipmap/compass" />
<ImageView
android:id="@+id/navinfo_map_logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:src="@mipmap/logo"
android:padding="@dimen/nimap_defalut_padding"></ImageView>
android:padding="@dimen/nimap_defalut_padding"
android:src="@mipmap/logo" />
<LinearLayout
android:id="@+id/navinfo_map_zoom_layer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="@dimen/nimap_defalut_padding"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:orientation="vertical">
android:layout_alignParentBottom="true"
android:orientation="vertical"
android:padding="@dimen/nimap_defalut_padding">
<ImageView
android:id="@+id/navinfo_map_zoom_in"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/icon_map_zoom_in"
android:background="@drawable/bg_nimap_default_button"
android:clickable="true"
android:focusable="true"
android:background="@drawable/bg_nimap_default_button"></ImageView>
android:src="@drawable/icon_map_zoom_in" />
<Space
android:layout_width="wrap_content"
android:layout_height="@dimen/nimap_defalut_padding"></Space>
android:layout_height="@dimen/nimap_defalut_padding" />
<ImageView
android:id="@+id/navinfo_map_zoom_out"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/icon_map_zoom_out"
android:background="@drawable/bg_nimap_default_button"
android:clickable="true"
android:focusable="true"
android:background="@drawable/bg_nimap_default_button"></ImageView>
android:src="@drawable/icon_map_zoom_out" />
</LinearLayout>
<LinearLayout
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
android:layout_centerInParent="true"
android:gravity="center"
android:orientation="vertical">
android:orientation="vertical"
android:visibility="gone">
<ImageView
android:id="@+id/main_tracking_cross"

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<network-security-config xmlns:tools="http://schemas.android.com/tools"
tools:ignore="MissingDefaultResource">
<base-config cleartextTrafficPermitted="true" />
</network-security-config>