| | |
| | | mountMethodToWindow(); |
| | | |
| | | }); |
| | | window.onload = function () { |
| | | //加载坐标点 |
| | | window.Android.loadMarker(); |
| | | }; |
| | | // window.onload = function () { |
| | | // console.log(window.onload); // 打印数组数据 |
| | | // //加载坐标点 |
| | | // window.Android.loadMarker(); |
| | | // }; |
| | | // 初始化地图 |
| | | function initMap() { |
| | | // 影像底图 |
| | |
| | | "&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}&tk=d8beed89b43160a9a185e5aff431f85d"; |
| | | //创建自定义图层对象 |
| | | //影像注记(地图上的地址) |
| | | var imgURL2 ="http://t0.tianditu.gov.cn/cia_w/wmts?" +"SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=cia&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles" + |
| | | "&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}" + |
| | | "&tk=d8beed89b43160a9a185e5aff431f85d"; |
| | | var imgURL2 = "http://t0.tianditu.gov.cn/cia_w/wmts?" + "SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=cia&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles" + |
| | | "&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}" + |
| | | "&tk=d8beed89b43160a9a185e5aff431f85d"; |
| | | var lay = new T.TileLayer(imageURL, { minZoom: 6, maxZoom: 18 }); |
| | | var lay2 = new T.TileLayer(imgURL2, { minZoom: 6, maxZoom: 18 }); |
| | | var config = { layers: [lay,lay2] }; |
| | | var config = { layers: [lay, lay2] }; |
| | | map = new T.Map("mapDiv", config); |
| | | var scale = new T.Control.Scale(); |
| | | //添加比例尺控件 |
| | |
| | | // 地图点击后获取经纬度 |
| | | function getLngLat(lnglat) { |
| | | console.log(lnglat.lng.toFixed(6) + "," + lnglat.lat.toFixed(6)); |
| | | addClickOverLay(lnglat); |
| | | // addClickOverLay(lnglat); |
| | | } |
| | | |
| | | // 点击后添加坐标点 |
| | |
| | | |
| | | |
| | | //设置地图中心点 |
| | | function setCenterAndZoom(lng, lat,thiszoom) { |
| | | zoom=thiszoom; |
| | | function setCenterAndZoom(lng, lat, thiszoom) { |
| | | zoom = thiszoom; |
| | | console.log("function》》》》》setCenterAndZoom>>>>lng:" + lng + ",lat:" + lat); |
| | | map.centerAndZoom(new T.LngLat(lng, lat), zoom); |
| | | } |
| | |
| | | window.showToast = showToast; |
| | | window.addMarker = addMarker; |
| | | window.setCenterAndZoom = setCenterAndZoom; |
| | | window.updateLocation=updateLocation; |
| | | window.updateLocation = updateLocation; |
| | | window.aginShowLocation = aginShowLocation; |
| | | window.cleanLocationLay = cleanLocationLay; |
| | | window.updateInspectionLocation = updateInspectionLocation; |
| | | window.cleanLoclLay = cleanLoclLay; |
| | | |
| | | } |
| | | |
| | | // 调用原生安卓方法显示取水口详情 |
| | |
| | | } |
| | | |
| | | // 点击标注的事件 |
| | | function addMarkerListener(data) { |
| | | function addMarkerListener(id,data) { |
| | | chageMarkerIcon(data); |
| | | showWaterIntakeDetail("模拟数据"); |
| | | showWaterIntakeDetail(id); |
| | | } |
| | | |
| | | // 修改点击标注的图标 |
| | |
| | | return data1.lat === data2.lat && data1.lng === data2.lng; |
| | | } |
| | | //添加从原生传过来的坐标并显示在地图上 |
| | | function addMarker(jsonData) { |
| | | function addMarker(id,lng,lat,name) { |
| | | console.log("function》》》》》addMarker"); |
| | | var array = JSON.parse(jsonData); |
| | | |
| | | var icon = new T.Icon({ |
| | | iconUrl: markerBluePath, |
| | | iconSize: new T.Point(27, 27), |
| | | iconAnchor: new T.Point(10, 25) |
| | | }); |
| | | 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) |
| | | }); |
| | | map.addOverLay(marker); // 将标注添加到地图中 |
| | | let label = new T.Label({ |
| | | text: name, |
| | | 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); |
| | | return "addMarker加载成功" |
| | | } |
| | | //更新定位坐标 |
| | | 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 }); |
| | | map.addOverLay(locationMarker); |
| | | map.panTo(newPoint); |
| | | } |
| | | //保存定位坐标生成轨迹 |
| | | var path=[]; |
| | | var lineLayer = new T.Polyline([], { color: 'red', weight: 3, opacity: 0.8 }); |
| | | |
| | | function updateLocation(log,lat){ |
| | | var lastLat=lat; |
| | | var path = []; |
| | | var lineLayer = new T.Polyline([], { color: '#ff4500', weight: 3, opacity: 0.8 }); |
| | | let locationMarker; |
| | | function updateInspectionLocation(log, lat) { |
| | | var lastLat = lat; |
| | | // const intervalId = setInterval(() => { |
| | | // lastLat=lastLat+0.0001; |
| | | var newPoint = new T.LngLat(log,lastLat); |
| | | path.push(newPoint); |
| | | lineLayer.setLngLats(path); |
| | | map.addOverLay(lineLayer); |
| | | // 移动地图视角到最后一个位置 |
| | | map.panTo(newPoint); |
| | | // lastLat=lastLat+0.0001; |
| | | var newPoint = new T.LngLat(log, lastLat); |
| | | path.push(newPoint); |
| | | lineLayer.setLngLats(path); |
| | | map.addOverLay(lineLayer); |
| | | // 移动地图视角到最后一个位置 |
| | | |
| | | // }, 500); |
| | | |
| | | } |
| | | |
| | | var aginPath = []; |
| | | var oldLineLayer = new T.Polyline([], { color: '#ff4500', weight: 3, opacity: 0.8 }); |
| | | //显示因异常关闭的巡检记录 |
| | | function aginShowLocation(lng, lat) { |
| | | // 调用 Android 提供的接口,获取数据 |
| | | console.log("aginShowLocation>>lng:" + lng + ">>>lat:" + lat); |
| | | var newPoint = new T.LngLat(lng, lat); |
| | | aginPath.push(newPoint); |
| | | oldLineLayer.setLngLats(aginPath); |
| | | map.addOverLay(oldLineLayer); |
| | | } |
| | | //清除巡检记录轨迹 |
| | | function cleanLocationLay() { |
| | | if (lineLayer) { |
| | | map.removeOverLay(lineLayer); |
| | | path = [] |
| | | } |
| | | if (locationMarker) { |
| | | map.removeOverLay(locationMarker); |
| | | } |
| | | if (oldLineLayer) { |
| | | aginPath = [] |
| | | map.removeOverLay(oldLineLayer); |
| | | } |
| | | } |
| | | //清除本地定位坐标位置 |
| | | function cleanLoclLay() { |
| | | if (locationMarker) { |
| | | map.removeOverLay(locationMarker); |
| | | } |
| | | } |
| | | |
| | | |
| | | })(); |
| | | |