From 20c39a4a121a70c3744bf1398797297028468027 Mon Sep 17 00:00:00 2001 From: userGyl Date: Mon, 13 Apr 2026 16:38:46 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=B7=E5=BC=8F=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/lnkj/ln_jq_app/NativeMapView.java | 64 +++++++++++++++---- .../src/main/res/drawable/rounded_top_bg.xml | 4 +- 2 files changed, 52 insertions(+), 16 deletions(-) diff --git a/ln_jq_app/android/app/src/main/java/com/lnkj/ln_jq_app/NativeMapView.java b/ln_jq_app/android/app/src/main/java/com/lnkj/ln_jq_app/NativeMapView.java index ae3d455..e2f9358 100644 --- a/ln_jq_app/android/app/src/main/java/com/lnkj/ln_jq_app/NativeMapView.java +++ b/ln_jq_app/android/app/src/main/java/com/lnkj/ln_jq_app/NativeMapView.java @@ -263,7 +263,7 @@ public class NativeMapView implements PlatformView, LocationSource, AMapLocation FrameLayout.LayoutParams bottomParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); bottomParams.gravity = Gravity.BOTTOM; container.addView(bottomContainer, bottomParams); - container.setPadding(0,0,0,dp2px(65)); + container.setPadding(0, 0, 0, dp2px(65)); // --- 模式选择菜单 --- @@ -272,7 +272,7 @@ public class NativeMapView implements PlatformView, LocationSource, AMapLocation // 布局参数:位于规划按钮上方 FrameLayout.LayoutParams menuParams = new FrameLayout.LayoutParams(dp2px(130), ViewGroup.LayoutParams.WRAP_CONTENT); menuParams.gravity = Gravity.BOTTOM | Gravity.END; - menuParams.setMargins(0, 0, dp2px(15), dp2px(330)); // 高度根据按钮位置调整 + menuParams.setMargins(0, 0, dp2px(15), dp2px(230)); // 高度根据按钮位置调整 container.addView(modeMenu, menuParams); @@ -296,7 +296,7 @@ public class NativeMapView implements PlatformView, LocationSource, AMapLocation int layoutSize = dp2px(44); FrameLayout.LayoutParams toggleParams = new FrameLayout.LayoutParams(layoutSize, layoutSize); toggleParams.gravity = Gravity.BOTTOM | Gravity.END; - toggleParams.setMargins(0, 0, dp2px(12), dp2px(340)); // 位于定位按钮上方 + toggleParams.setMargins(0, 0, dp2px(12), dp2px(210)); // 位于定位按钮上方 container.addView(planToggleBtn, toggleParams); // --- 右下角定位按钮 --- @@ -316,7 +316,7 @@ public class NativeMapView implements PlatformView, LocationSource, AMapLocation aMap.animateCamera(CameraUpdateFactory.newLatLngZoom(currentLatLng, 15f)); }); FrameLayout.LayoutParams locParams = new FrameLayout.LayoutParams(layoutSize, layoutSize); - locParams.setMargins(0, 0, dp2px(15), dp2px(285)); // 调高一点,避开底部的面板 + locParams.setMargins(0, 0, dp2px(15), dp2px(150)); // 调高一点,避开底部的面板 locParams.gravity = Gravity.BOTTOM | Gravity.END; container.addView(mLocBtn, locParams); } @@ -325,7 +325,7 @@ public class NativeMapView implements PlatformView, LocationSource, AMapLocation private LinearLayout createDetailPanel(Context context) { LinearLayout panel = new LinearLayout(context); panel.setOrientation(LinearLayout.VERTICAL); - int padding = dp2px(20); + int padding = dp2px(15); panel.setPadding(padding, padding, padding, padding); // --- (包含标题和关闭按钮) --- @@ -347,11 +347,7 @@ public class NativeMapView implements PlatformView, LocationSource, AMapLocation ivClose.setScaleType(ImageView.ScaleType.CENTER_INSIDE); ivClose.setPadding(dp2px(5), dp2px(5), dp2px(5), dp2px(5)); ivClose.setOnClickListener(v -> { - if (detailPanel != null) - detailPanel.setVisibility(View.GONE); - searchArea.setVisibility(View.VISIBLE); - planToggleBtn.setVisibility(View.VISIBLE); - mLocBtn.setVisibility(View.VISIBLE); + resetView(); }); LinearLayout.LayoutParams closeParams = new LinearLayout.LayoutParams(dp2px(28), dp2px(28)); @@ -430,6 +426,14 @@ public class NativeMapView implements PlatformView, LocationSource, AMapLocation return panel; } + private void resetView() { + if (detailPanel != null) + detailPanel.setVisibility(View.GONE); + searchArea.setVisibility(View.VISIBLE); + planToggleBtn.setVisibility(View.VISIBLE); + mLocBtn.setVisibility(View.VISIBLE); + } + private boolean isGetInputtips = false; private void calculateRouteBeforeNavi() { @@ -811,6 +815,18 @@ public class NativeMapView implements PlatformView, LocationSource, AMapLocation aMap.setMyLocationEnabled(true); aMap.setOnMarkerClickListener(this); + // 添加地图点击监听,当 detailPanel 显示时点击地图就执行 resetView + aMap.setOnMapClickListener(latLng -> { + if (detailPanel != null && detailPanel.getVisibility() == View.VISIBLE) { + resetView(); + } + }); + aMap.setOnPOIClickListener(poi -> { + if (detailPanel != null && detailPanel.getVisibility() == View.VISIBLE) { + resetView(); + } + }); + MyLocationStyle myLocationStyle = new MyLocationStyle(); try { Bitmap carBitmap = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.car); @@ -823,7 +839,7 @@ public class NativeMapView implements PlatformView, LocationSource, AMapLocation } myLocationStyle.anchor(0.5f, 0.5f); - myLocationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE_NO_CENTER); + myLocationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_SHOW); aMap.setMyLocationStyle(myLocationStyle); aMap.getUiSettings().setZoomControlsEnabled(false); aMap.getUiSettings().setLogoPosition(AMapOptions.LOGO_POSITION_BOTTOM_LEFT); @@ -1035,6 +1051,7 @@ public class NativeMapView implements PlatformView, LocationSource, AMapLocation dataMap.put("latLng", latLng); dataMap.put("stationId", stationId); dataMap.put("address", address); + dataMap.put("name", name); m.setObject(dataMap); stationMarkers.add(m); @@ -1045,7 +1062,27 @@ public class NativeMapView implements PlatformView, LocationSource, AMapLocation //地图选点 for (Marker m : stationMarkers) { - m.setIcon(BitmapDescriptorFactory.fromResource(m.equals(marker) ? R.drawable.ic_marker : R.drawable.ic_un_marker)); + Object obj = m.getObject(); + if (obj instanceof Map) { + Map dataMap = (Map) obj; + String name = (String) dataMap.get("name"); + + if (name != null) { + // 截取显示名称(最多7个字符) + String displayName = name.length() > 7 ? name.substring(0, 7) + "..." : + name; + boolean isSelected = m.equals(marker); + + // 使用 getMarkerIconWithText 创建带文字的图标 + BitmapDescriptor icon = getMarkerIconWithText(mContext, displayName, + isSelected); + m.setIcon(icon); + } else { + // 如果没有 name,降级到直接设置图标 + m.setIcon(BitmapDescriptorFactory.fromResource(m.equals(marker) ? + R.drawable.ic_marker : R.drawable.ic_un_marker)); + } + } } @@ -1281,13 +1318,12 @@ public class NativeMapView implements PlatformView, LocationSource, AMapLocation tv.setPadding(dp2px(15), dp2px(12), dp2px(15), dp2px(12)); tv.setGravity(Gravity.CENTER); if (isHighlight) { - tv.setTextColor(Color.WHITE); // 顶部圆角绿色背景 tv.setBackground(getTopRoundedDrawable(Color.parseColor("#27AE60"), 12)); } else { - tv.setTextColor(Color.parseColor("#666666")); tv.setBackgroundColor(Color.TRANSPARENT); } + tv.setTextColor(Color.parseColor(isHighlight ? "#ffffffff" : "#ffc9cdd4")); return tv; } diff --git a/ln_jq_app/android/app/src/main/res/drawable/rounded_top_bg.xml b/ln_jq_app/android/app/src/main/res/drawable/rounded_top_bg.xml index a52964d..a3b85c5 100644 --- a/ln_jq_app/android/app/src/main/res/drawable/rounded_top_bg.xml +++ b/ln_jq_app/android/app/src/main/res/drawable/rounded_top_bg.xml @@ -2,8 +2,8 @@ \ No newline at end of file