From 32275aa66faa5371467e291b7d19a5e782f8aade Mon Sep 17 00:00:00 2001
From: zuoxiao <470321431@qq.com>
Date: 星期三, 18 十二月 2024 16:47:18 +0800
Subject: [PATCH] 1.修改取水口坐标相关代码
---
app/src/main/assets/js/map.js | 235 ++++++++++++++++++++++++++++++----------------------------
1 files changed, 122 insertions(+), 113 deletions(-)
diff --git a/app/src/main/assets/js/map.js b/app/src/main/assets/js/map.js
index 367686b..8309b68 100644
--- a/app/src/main/assets/js/map.js
+++ b/app/src/main/assets/js/map.js
@@ -4,11 +4,29 @@
const markerBalckPath = 'img/marker_black.svg';
const markerRedPath = 'img/marker_red.svg';
const markerBluePath = 'img/marker_blue.svg';
+ const centerPin = 'img/push_pin.svg';
let map;
let lastMarker = null;
let lastClickedMarker = null;
let isShowWaterIntakeDetail = false;
let zoom = 12;
+
+ // 灏嗘柟娉曟寕杞藉埌 window 涓�
+ function mountMethodToWindow() {
+ window.locationOverLay = locationOverLay;
+ window.showToast = showToast;
+ window.addMarker = addMarker;
+ window.setCenterAndZoom = setCenterAndZoom;
+ window.updateLocation = updateLocation;
+ window.aginShowLocation = aginShowLocation;
+ window.cleanLocationLay = cleanLocationLay;
+ window.updateInspectionLocation = updateInspectionLocation;
+ window.cleanLoclLay = cleanLoclLay;
+ window.showPin = showPin;
+ window.cancelPin = cancelPin;
+ window.refreshMarker = refreshMarker;
+
+ }
document.addEventListener('DOMContentLoaded', function () {
@@ -18,11 +36,7 @@
mountMethodToWindow();
});
- window.onload = function () {
- console.log(window.onload); // 鎵撳嵃鏁扮粍鏁版嵁
- //鍔犺浇鍧愭爣鐐�
- window.Android.loadMarker();
- };
+
// 鍒濆鍖栧湴鍥�
function initMap() {
// 褰卞儚搴曞浘
@@ -87,47 +101,6 @@
}
}
- // 妯℃嫙娣诲姞鍙栨按鍙f爣娉�
- function buttonOverLay() {
- map.clearOverLays(); // 娓呯悊鍦板浘涓婄殑鎵�鏈夎鐩栫墿
-
- let data_info = [
- [116.417854, 39.921988, "235鍙栨按鍙�"],
- [116.406605, 39.921585, "237鍙栨按鍙�"],
- [116.412222, 39.912345, "236鍙栨按鍙�"]
- ];
-
- for (let i = 0; i < data_info.length; i++) {
- let icon = new T.Icon({
- iconUrl: markerBluePath,
- iconSize: new T.Point(27, 27),
- iconAnchor: new T.Point(10, 25)
- });
-
- let marker = new T.Marker(
- new T.LngLat(data_info[i][0], data_info[i][1]), // 鍒涘缓鏍囨敞
- { icon: icon }
- );
-
- marker.addEventListener("click", function (data) {
- addMarkerListener(data);
- });
-
- map.addOverLay(marker); // 灏嗘爣娉ㄦ坊鍔犲埌鍦板浘涓�
-
- let label = new T.Label({
- text: data_info[i][2],
- position: marker.getLngLat(),
- offset: new T.Point(-50, 10), // 璁剧疆鏍囨敞鏂囧瓧鐨勪綅缃�
- opacity: 1, // 璁剧疆鏂囨湰鐨勬樉绀轰笉閫忔槑搴︼紙鑼冨洿0-1锛�
- });
- label.setBorderLine(0); // 璁剧疆鏂囨湰鐨勮竟妗嗙嚎瀹�
- label.setBackgroundColor("transparent"); // 璁剧疆鏂囨湰鐨勮儗鏅壊锛堥�忔槑鑹诧級
- label.setFontColor("#0000FF");
- label.setFontSize(10);
- map.addOverLay(label);
- }
- }
// 鏄剧ず鏍囨敞鐐瑰嚮鍚庣殑绐楀彛
function openInfo(content, e) {
@@ -161,19 +134,7 @@
}
- // 灏嗘柟娉曟寕杞藉埌 window 涓�
- function mountMethodToWindow() {
- window.locationOverLay = locationOverLay;
- window.showToast = showToast;
- window.addMarker = addMarker;
- window.setCenterAndZoom = setCenterAndZoom;
- window.updateLocation = updateLocation;
- window.aginShowLocation = aginShowLocation;
- window.cleanLocationLay = cleanLocationLay;
- window.updateInspectionLocation=updateInspectionLocation;
- window.cleanLoclLay=cleanLoclLay;
- }
// 璋冪敤鍘熺敓瀹夊崜鏂规硶鏄剧ず鍙栨按鍙h鎯�
function showWaterIntakeDetail(data) {
@@ -183,30 +144,36 @@
// 璋冪敤鍘熺敓瀹夊崜鏂规硶闅愯棌鍙栨按鍙h鎯�
function closeWaterIntakeDetail(data) {
- if (lastClickedMarker !== null) {
- // 濡傛灉鏈夌偣鍑诲彇姘村彛鍒欏皢鍙栨按鍙f仮澶嶆垚榛戣壊
- // 涓婃鐐瑰嚮鐨勬爣娉ㄦ敼涓洪粦鑹�
- var defaulticon = new T.Icon({
- iconUrl: markerBluePath,
- iconSize: new T.Point(27, 27),
- iconAnchor: new T.Point(10, 25)
- });
- lastClickedMarker.setIcon(defaulticon);
+ 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);
+ }
+ if (isShowWaterIntakeDetail) {
+ // 鍋囧鏄剧ず浜嗗彇姘村彛璇︽儏鍒欓殣钘忓彇姘村彛璇︽儏
+ isShowWaterIntakeDetail = false;
+ window.Android.closeWaterIntakeView();
+ } else {
+ // 鍋囧娌℃湁鏄剧ず鍙栨按鍙e垯娣诲姞鐐瑰嚮鐨勫潗鏍�
+ getLngLat(data.lnglat);
+ }
}
- if (isShowWaterIntakeDetail) {
- // 鍋囧鏄剧ず浜嗗彇姘村彛璇︽儏鍒欓殣钘忓彇姘村彛璇︽儏
- isShowWaterIntakeDetail = false;
- window.Android.closeWaterIntakeView();
- } else {
- // 鍋囧娌℃湁鏄剧ず鍙栨按鍙e垯娣诲姞鐐瑰嚮鐨勫潗鏍�
- getLngLat(data.lnglat);
- }
+
}
// 鐐瑰嚮鏍囨敞鐨勪簨浠�
- function addMarkerListener(data) {
- chageMarkerIcon(data);
- showWaterIntakeDetail("妯℃嫙鏁版嵁");
+ function addMarkerListener(id, data) {
+ if (!isShowCenterPin) {
+ chageMarkerIcon(data);
+ showWaterIntakeDetail(id);
+ }
+
}
// 淇敼鐐瑰嚮鏍囨敞鐨勫浘鏍�
@@ -216,8 +183,8 @@
// 鐐瑰嚮鍚庡浘鏍�
var clickedIcon = new T.Icon({
iconUrl: markerRedPath,
- iconSize: new T.Point(27, 27),
- iconAnchor: new T.Point(10, 25)
+ iconSize: new T.Point(28, 28),
+ iconAnchor: new T.Point(14, 28)
});
// 璁剧疆褰撳墠鐐瑰嚮鐨� marker 涓虹偣鍑诲悗鍥炬爣
currentMarker.setIcon(clickedIcon);
@@ -226,13 +193,14 @@
if (!isEqualsLngLat(data.target.getLngLat(), lastClickedMarker.getLngLat())) {
var defaulticon = new T.Icon({
iconUrl: markerBluePath,
- iconSize: new T.Point(27, 27),
- iconAnchor: new T.Point(10, 25)
+ iconSize: new T.Point(28, 28),
+ iconAnchor: new T.Point(14, 28)
});
lastClickedMarker.setIcon(defaulticon);
}
}
lastClickedMarker = data.target;
+ map.panTo(currentMarker.getLngLat());
}
//璋冨畨鍗撳師鐢�
function showToast() {
@@ -243,37 +211,49 @@
function isEqualsLngLat(data1, data2) {
return data1.lat === data2.lat && data1.lng === data2.lng;
}
+ function addMarker(id, lng, lat, name) {
+ addMarker(id, lng, lat, name, false)
+ }
//娣诲姞浠庡師鐢熶紶杩囨潵鐨勫潗鏍囧苟鏄剧ず鍦ㄥ湴鍥句笂
- function addMarker(jsonData) {
- console.log("function銆嬨�嬨�嬨�嬨�媋ddMarker");
- var array = JSON.parse(jsonData);
+ 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: markerBluePath,
- iconSize: new T.Point(27, 27),
- iconAnchor: new T.Point(10, 25)
+ iconUrl: iconUrl,
+ iconSize: new T.Point(28, 28),
+ iconAnchor: new T.Point(14, 28)
});
- array.forEach(element => {
- let marker = new T.Marker(
- new T.LngLat(element[0], element[1]) // 鍒涘缓鏍囨敞
- , { icon: icon });
- //娣诲姞鐐瑰嚮浜嬩欢
- marker.addEventListener("click", (data) => {
- addMarkerListener(data)
- });
- map.addOverLay(marker); // 灏嗘爣娉ㄦ坊鍔犲埌鍦板浘涓�
- let label = new T.Label({
- text: element[2],
- position: marker.getLngLat(),
- offset: new T.Point(-35, 8), // 璁剧疆鏍囨敞鏂囧瓧鐨勪綅缃�
- opacity: 1, // 璁剧疆鏂囨湰鐨勬樉绀轰笉閫忔槑搴︼紙鑼冨洿0-1锛�
- });
- label.setBorderLine(0); // 璁剧疆鏂囨湰鐨勮竟妗嗙嚎瀹�
- label.setBackgroundColor("transparent"); // 璁剧疆鏂囨湰鐨勮儗鏅壊锛堥�忔槑鑹诧級
- label.setFontColor("#0000FF");
- label.setFontSize(10);
- map.addOverLay(label);
+ let marker = new T.Marker(
+ new T.LngLat(lng, lat) // 鍒涘缓鏍囨敞
+ , { icon: icon });
+ //娣诲姞鐐瑰嚮浜嬩欢
+ marker.addEventListener("click", (data) => {
+ addMarkerListener(id, data)
});
- return "addMarker鍔犺浇鎴愬姛"
+
+ let label = new T.Label({
+ text: `<div style='position:absolute;left:-50%;transform: translateX(-50%);'>${name}<div>`,
+ position: marker.getLngLat(),
+ offset: new T.Point(0, 8), // 璁剧疆鏍囨敞鏂囧瓧鐨勪綅缃�
+ opacity: 1, // 璁剧疆鏂囨湰鐨勬樉绀轰笉閫忔槑搴︼紙鑼冨洿0-1锛�
+ });
+ label.setBorderLine(0); // 璁剧疆鏂囨湰鐨勮竟妗嗙嚎瀹�
+ label.setBackgroundColor("transparent"); // 璁剧疆鏂囨湰鐨勮儗鏅壊锛堥�忔槑鑹诧級
+ label.setFontColor("#FFFFFF");
+ label.setFontSize(10);
+ marker.label = label;
+ if (isRed){
+ lastClickedMarker=marker;
+ }
+ map.addOverLay(label);
+ map.addOverLay(marker); // 灏嗘爣娉ㄦ坊鍔犲埌鍦板浘涓�
+ return "addMarker鍔犺浇鎴愬姛 id:" + id
}
//鏇存柊瀹氫綅鍧愭爣
function updateLocation(log, lat) {
@@ -303,7 +283,7 @@
lineLayer.setLngLats(path);
map.addOverLay(lineLayer);
// 绉诲姩鍦板浘瑙嗚鍒版渶鍚庝竴涓綅缃�
-
+
// }, 500);
}
@@ -322,22 +302,51 @@
function cleanLocationLay() {
if (lineLayer) {
map.removeOverLay(lineLayer);
- path=[]
+ path = []
}
if (locationMarker) {
map.removeOverLay(locationMarker);
}
if (oldLineLayer) {
- aginPath=[]
+ aginPath = []
map.removeOverLay(oldLineLayer);
}
}
//娓呴櫎鏈湴瀹氫綅鍧愭爣浣嶇疆
- function cleanLoclLay(){
+ function cleanLoclLay() {
if (locationMarker) {
map.removeOverLay(locationMarker);
}
}
+ //鏄惁鏄剧ず浜嗗湴鍥句腑蹇冪殑閽堢敤鏉ヤ慨鏀瑰潗鏍�
+ var isShowCenterPin;
+ //寮�濮嬭幏鍙栧睆骞曚腑闂村畾浣�
+ function showPin(lng, lat) {
+ var newPoint = new T.LngLat(lng, lat);
+ map.panTo(newPoint);
+ isShowCenterPin = true;
+ map.addEventListener("moveend", mapMoveEnd);
+ window.Android.refreshCenter(map.getCenter().getLng(), map.getCenter().getLat());
+
+ }
+ //鍙栨秷淇敼瀹氫綅
+ function cancelPin() {
+ isShowCenterPin = false;
+ }
+
+ //鎴愬姛淇敼鍙栨按鍙g粡绾害鍚庡埛鏂板彇姘村彛浣嶇疆
+ function refreshMarker(id, lng, lat, name) {
+ map.removeOverLay(lastClickedMarker.label);
+ map.removeOverLay(lastClickedMarker);
+ addMarker(id, lng, lat, name, true);
+ }
+
+
+ function mapMoveEnd(e) {
+ var center = e.target.getCenter();
+ console.log("lng:" + center.getLng() + " lat:" + center.getLat())
+ window.Android.refreshCenter(center.getLng(), center.getLat());
+ }
})();
--
Gitblit v1.8.0