| | |
| | | window.updateInspectionLocation = updateInspectionLocation; |
| | | window.cleanLoclLay = cleanLoclLay; |
| | | window.showPin = showPin; |
| | | window.cancelPin = cancelPin; |
| | | window.refreshMarker = refreshMarker; |
| | | |
| | | } |
| | | |
| | |
| | | mountMethodToWindow(); |
| | | |
| | | }); |
| | | // window.onload = function () { |
| | | // console.log(window.onload); // 打印数组数据 |
| | | // //加载坐标点 |
| | | // window.Android.loadMarker(); |
| | | // }; |
| | | |
| | | // 初始化地图 |
| | | function initMap() { |
| | | // 影像底图 |
| | |
| | | |
| | | // 调用原生安卓方法隐藏取水口详情 |
| | | function closeWaterIntakeDetail(data) { |
| | | if (lastClickedMarker !== null) { |
| | | // 如果有点击取水口则将取水口恢复成黑色 |
| | | // 上次点击的标注改为黑色 |
| | | var defaulticon = new T.Icon({ |
| | | iconUrl: markerBluePath, |
| | | iconSize: new T.Point(28, 28), |
| | | iconAnchor: new T.Point(14, 28) |
| | | }); |
| | | lastClickedMarker.setIcon(defaulticon); |
| | | if (!isShowCenterPin) { |
| | | if (lastClickedMarker !== null) { |
| | | // 如果有点击取水口则将取水口恢复成黑色 |
| | | // 上次点击的标注改为黑色 |
| | | 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 { |
| | | // 假如没有显示取水口则添加点击的坐标 |
| | | getLngLat(data.lnglat); |
| | | } |
| | | } |
| | | if (isShowWaterIntakeDetail) { |
| | | // 假如显示了取水口详情则隐藏取水口详情 |
| | | isShowWaterIntakeDetail = false; |
| | | window.Android.closeWaterIntakeView(); |
| | | } else { |
| | | // 假如没有显示取水口则添加点击的坐标 |
| | | getLngLat(data.lnglat); |
| | | } |
| | | |
| | | } |
| | | |
| | | // 点击标注的事件 |
| | | function addMarkerListener(id, data) { |
| | | chageMarkerIcon(data); |
| | | showWaterIntakeDetail(id); |
| | | if (!isShowCenterPin) { |
| | | chageMarkerIcon(data); |
| | | showWaterIntakeDetail(id); |
| | | }else { |
| | | showToast("当前正在修改选中取水口的经纬度,完成或退出后才可选择其他!"); |
| | | } |
| | | |
| | | } |
| | | |
| | | // 修改点击标注的图标 |
| | |
| | | } |
| | | } |
| | | 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) { |
| | | return data1.lat === data2.lat && data1.lng === data2.lng; |
| | | } |
| | | //添加从原生传过来的坐标并显示在地图上 |
| | | function addMarker(id, lng, lat, name) { |
| | | console.log("function》》》》》addMarker"); |
| | | addMarker(id, lng, lat, name, false) |
| | | } |
| | | //添加从原生传过来的坐标并显示在地图上 |
| | | function addMarker(id, lng, lat, name, isRed) { |
| | | console.log("function》》》》》addMarker>>>id:" + id); |
| | | |
| | | var iconUrl; |
| | | if (isRed) { |
| | | iconUrl = markerRedPath; |
| | | } else { |
| | | iconUrl = markerBluePath; |
| | | } |
| | | var icon = new T.Icon({ |
| | | iconUrl: markerBluePath, |
| | | iconUrl: iconUrl, |
| | | iconSize: new T.Point(28, 28), |
| | | iconAnchor: new T.Point(14, 28) |
| | | }); |
| | |
| | | marker.addEventListener("click", (data) => { |
| | | addMarkerListener(id, data) |
| | | }); |
| | | map.addOverLay(marker); // 将标注添加到地图中 |
| | | |
| | | let label = new T.Label({ |
| | | text: `<div style='position:absolute;left:-50%;transform: translateX(-50%);'>${name}<div>`, |
| | | position: marker.getLngLat(), |
| | |
| | | label.setBackgroundColor("transparent"); // 设置文本的背景色(透明色) |
| | | label.setFontColor("#FFFFFF"); |
| | | label.setFontSize(10); |
| | | marker.label = label; |
| | | if (isRed){ |
| | | lastClickedMarker=marker; |
| | | } |
| | | map.addOverLay(label); |
| | | return "addMarker加载成功" |
| | | map.addOverLay(marker); // 将标注添加到地图中 |
| | | return "addMarker加载成功 id:" + id |
| | | } |
| | | //更新定位坐标 |
| | | function updateLocation(log, lat) { |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | //在地图上显示中心点 |
| | | var pinMarker; |
| | | function showPin() { |
| | | var icon = new T.Icon({ |
| | | iconUrl: centerPin, |
| | | iconSize: new T.Point(28, 28), |
| | | iconAnchor: new T.Point(14, 28) |
| | | }); |
| | | pinMarker = new T.Marker( |
| | | new T.LngLat(map.getCenter().getLng(), map.getCenter().getLat()) // 创建标注 |
| | | , { icon: icon }); |
| | | map.addOverLay(pinMarker); // 将标注添加到地图中 |
| | | map.addEventListener("moveend", MapMoveend); |
| | | //是否显示了地图中心的针用来修改坐标 |
| | | 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()); |
| | | return true; |
| | | } |
| | | //取消修改定位 |
| | | function cancelPin() { |
| | | isShowCenterPin = false; |
| | | } |
| | | |
| | | function MapMoveend(e) { |
| | | map.removeOverLay(pinMarker); |
| | | var icon = new T.Icon({ |
| | | iconUrl: centerPin, |
| | | iconSize: new T.Point(28, 28), |
| | | iconAnchor: new T.Point(14, 28) |
| | | }); |
| | | //成功修改取水口经纬度后刷新取水口位置 |
| | | 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()) |
| | | pinMarker = new T.Marker( |
| | | new T.LngLat(center.getLng(), center.getLat()) // 创建标注 |
| | | , { icon: icon }); |
| | | map.addOverLay(pinMarker); // 将标注添加到地图中 |
| | | window.Android.refreshCenter(center.getLng(), center.getLat()); |
| | | } |
| | | |
| | | })(); |