From 50f9b82ac862652e88444d727a32e0da1d824e9e Mon Sep 17 00:00:00 2001
From: zuoxiao <470321431@qq.com>
Date: 星期一, 13 一月 2025 15:57:06 +0800
Subject: [PATCH] 1.分水房相关 2.删除极光推送相关配置 3.优化图片显示相关
---
app/src/main/assets/js/map.js | 135 ++++++++++++++++++++++++--------------------
1 files changed, 73 insertions(+), 62 deletions(-)
diff --git a/app/src/main/assets/js/map.js b/app/src/main/assets/js/map.js
index 8309b68..a13de46 100644
--- a/app/src/main/assets/js/map.js
+++ b/app/src/main/assets/js/map.js
@@ -1,10 +1,18 @@
(function () {
- // 鍥剧墖璺緞
- const locationIMGPath = 'img/location.png';
- const markerBalckPath = 'img/marker_black.svg';
- const markerRedPath = 'img/marker_red.svg';
- const markerBluePath = 'img/marker_blue.svg';
- const centerPin = 'img/push_pin.svg';
+ // 寤鸿灏嗚繖浜涘父閲忕Щ鍒颁竴涓厤缃璞′腑缁熶竴绠$悊
+ const CONFIG = {
+ IMAGES: {
+ LOCATION: 'img/location.png',
+ MARKER_BLACK: 'img/marker_black.svg',
+ MARKER_RED: 'img/marker_red.svg',
+ MARKER_BLUE: 'img/marker_blue.svg',
+ CENTER_PIN: 'img/push_pin.svg'
+ },
+ MAP: {
+ DEFAULT_ZOOM: 12,
+ TIANDITU_KEY: 'd8beed89b43160a9a185e5aff431f85d'
+ }
+ };
let map;
let lastMarker = null;
let lastClickedMarker = null;
@@ -115,13 +123,15 @@
function locationOverLay(lng, lag) {
console.log("function銆嬨�嬨�嬨�嬨�媗ocationOverLay");
map.centerAndZoom(new T.LngLat(lng, lag), map.getZoom());
-
let icon = new T.Icon({
- iconUrl: locationIMGPath,
- iconSize: new T.Point(27, 27),
- iconAnchor: new T.Point(10, 25)
+ iconUrl: CONFIG.IMAGES.LOCATION,
+ iconSize: new T.Point(20, 20),
+ iconAnchor: new T.Point(10, 10)
});
- let marker = new T.Marker(new T.LngLat(lng, lag), { icon: icon });
+ let marker = new T.Marker(
+ new T.LngLat(lng, lag),
+ { icon: icon }
+ );
map.addOverLay(marker);
}
@@ -146,14 +156,7 @@
function closeWaterIntakeDetail(data) {
if (!isShowCenterPin) {
if (lastClickedMarker !== null) {
- // 濡傛灉鏈夌偣鍑诲彇姘村彛鍒欏皢鍙栨按鍙f仮澶嶆垚榛戣壊
- // 涓婃鐐瑰嚮鐨勬爣娉ㄦ敼涓洪粦鑹�
- var defaulticon = new T.Icon({
- iconUrl: markerBluePath,
- iconSize: new T.Point(28, 28),
- iconAnchor: new T.Point(14, 28)
- });
- lastClickedMarker.setIcon(defaulticon);
+ lastClickedMarker.setIcon(createIcon(CONFIG.IMAGES.MARKER_BLUE));
}
if (isShowWaterIntakeDetail) {
// 鍋囧鏄剧ず浜嗗彇姘村彛璇︽儏鍒欓殣钘忓彇姘村彛璇︽儏
@@ -172,6 +175,8 @@
if (!isShowCenterPin) {
chageMarkerIcon(data);
showWaterIntakeDetail(id);
+ }else {
+ showToast("褰撳墠姝e湪淇敼閫変腑鍙栨按鍙g殑缁忕含搴︼紝瀹屾垚鎴栭��鍑哄悗鎵嶅彲閫夋嫨鍏朵粬锛�");
}
}
@@ -180,32 +185,20 @@
function chageMarkerIcon(data) {
// 鐐瑰嚮鐨勬爣娉ㄦ敼涓虹孩鑹�
var currentMarker = data.target;
- // 鐐瑰嚮鍚庡浘鏍�
- var clickedIcon = new T.Icon({
- iconUrl: markerRedPath,
- iconSize: new T.Point(28, 28),
- iconAnchor: new T.Point(14, 28)
- });
- // 璁剧疆褰撳墠鐐瑰嚮鐨� marker 涓虹偣鍑诲悗鍥炬爣
- currentMarker.setIcon(clickedIcon);
- // 鍒ゆ柇鐐瑰嚮鐨勪笉鏄悓涓�涓潗鏍�
+ currentMarker.setIcon(createIcon(CONFIG.IMAGES.MARKER_RED));
+
if (lastClickedMarker !== null) {
if (!isEqualsLngLat(data.target.getLngLat(), lastClickedMarker.getLngLat())) {
- var defaulticon = new T.Icon({
- iconUrl: markerBluePath,
- iconSize: new T.Point(28, 28),
- iconAnchor: new T.Point(14, 28)
- });
- lastClickedMarker.setIcon(defaulticon);
+ lastClickedMarker.setIcon(createIcon(CONFIG.IMAGES.MARKER_BLUE));
}
}
lastClickedMarker = data.target;
map.panTo(currentMarker.getLngLat());
}
//璋冨畨鍗撳師鐢�
- function showToast() {
+ function showToast(data) {
// 璋冪敤 JavaScript 鎺ュ彛瀵硅薄鐨勬柟娉�
- window.Android.showToast('Hello, Android!');
+ window.Android.showToast(data);
}
// 鍒ゆ柇涓や釜鍧愭爣鏄惁涓�鑷�
function isEqualsLngLat(data1, data2) {
@@ -218,20 +211,11 @@
function addMarker(id, lng, lat, name, isRed) {
console.log("function銆嬨�嬨�嬨�嬨�媋ddMarker>>>id:" + id);
- var iconUrl;
- if (isRed) {
- iconUrl = markerRedPath;
- } else {
- iconUrl = markerBluePath;
- }
- var icon = new T.Icon({
- iconUrl: iconUrl,
- iconSize: new T.Point(28, 28),
- iconAnchor: new T.Point(14, 28)
- });
+ const iconUrl = isRed ? CONFIG.IMAGES.MARKER_RED : CONFIG.IMAGES.MARKER_BLUE;
let marker = new T.Marker(
- new T.LngLat(lng, lat) // 鍒涘缓鏍囨敞
- , { icon: icon });
+ new T.LngLat(lng, lat),
+ { icon: createIcon(iconUrl) }
+ );
//娣诲姞鐐瑰嚮浜嬩欢
marker.addEventListener("click", (data) => {
addMarkerListener(id, data)
@@ -255,24 +239,28 @@
map.addOverLay(marker); // 灏嗘爣娉ㄦ坊鍔犲埌鍦板浘涓�
return "addMarker鍔犺浇鎴愬姛 id:" + id
}
- //鏇存柊瀹氫綅鍧愭爣
+ //鏇存柊浣嶅潗鏍�
function updateLocation(log, lat) {
- let icon = new T.Icon({
- iconUrl: locationIMGPath,
- iconSize: new T.Point(20, 20),
- iconAnchor: new T.Point(10, 10)
- });
if (locationMarker) {
map.removeOverLay(locationMarker);
}
var newPoint = new T.LngLat(log, lat);
- locationMarker = new T.Marker(newPoint, { icon: icon });
+ let icon = new T.Icon({
+ iconUrl: CONFIG.IMAGES.LOCATION,
+ iconSize: new T.Point(20, 20),
+ iconAnchor: new T.Point(10, 10)
+ });
+
+ locationMarker = new T.Marker(
+ newPoint,
+ { icon: icon }
+ );
map.addOverLay(locationMarker);
map.panTo(newPoint);
}
//淇濆瓨瀹氫綅鍧愭爣鐢熸垚杞ㄨ抗
var path = [];
- var lineLayer = new T.Polyline([], { color: '#ff4500', weight: 3, opacity: 0.8 });
+ var lineLayer = new T.Polyline([], { color: '#E9900A', weight: 3, opacity: 0.8 });
let locationMarker;
function updateInspectionLocation(log, lat) {
var lastLat = lat;
@@ -288,7 +276,7 @@
}
var aginPath = [];
- var oldLineLayer = new T.Polyline([], { color: '#ff4500', weight: 3, opacity: 0.8 });
+ var oldLineLayer = new T.Polyline([], { color: '#E9900A', weight: 3, opacity: 0.8 });
//鏄剧ず鍥犲紓甯稿叧闂殑宸℃璁板綍
function aginShowLocation(lng, lat) {
// 璋冪敤 Android 鎻愪緵鐨勬帴鍙o紝鑾峰彇鏁版嵁
@@ -328,7 +316,7 @@
isShowCenterPin = true;
map.addEventListener("moveend", mapMoveEnd);
window.Android.refreshCenter(map.getCenter().getLng(), map.getCenter().getLat());
-
+ return true;
}
//鍙栨秷淇敼瀹氫綅
function cancelPin() {
@@ -344,9 +332,32 @@
function mapMoveEnd(e) {
- var center = e.target.getCenter();
- console.log("lng:" + center.getLng() + " lat:" + center.getLat())
- window.Android.refreshCenter(center.getLng(), center.getLat());
+ debounce(() => {
+ const center = e.target.getCenter();
+ window.Android.refreshCenter(center.getLng(), center.getLat());
+ }, 300);
+ }
+
+ // 娣诲姞闃叉姈鍑芥暟
+ function debounce(fn, delay) {
+ let timer = null;
+ return function() {
+ if(timer) clearTimeout(timer);
+ timer = setTimeout(() => {
+ fn.apply(this, arguments);
+ }, delay);
+ }
+ }
+
+
+
+ // 鍒涘缓marker鍥炬爣鐨勬柟娉曞彲浠ユ娊鍙栧嚭鏉ュ鐢�
+ function createIcon(iconUrl, size = 28) {
+ return new T.Icon({
+ iconUrl: iconUrl,
+ iconSize: new T.Point(size, size),
+ iconAnchor: new T.Point(size/2, size)
+ });
}
})();
--
Gitblit v1.8.0