From a380286469db34b71ce4f86a3f348e668d90ceb6 Mon Sep 17 00:00:00 2001 From: Anne_LXM Date: Tue, 24 Sep 2024 20:45:41 +0800 Subject: [PATCH] =?UTF-8?q?test(map.test.js):=E8=A1=A5=E5=85=85map?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/component/map/map.test.js | 2 +- pages/component/map/map.uvue | 142 ++++++++++++++++++++++++++++++-- 2 files changed, 137 insertions(+), 7 deletions(-) diff --git a/pages/component/map/map.test.js b/pages/component/map/map.test.js index d354cf81..adfc8bef 100644 --- a/pages/component/map/map.test.js +++ b/pages/component/map/map.test.js @@ -17,7 +17,7 @@ describe('web-map', () => { }); it('Check MapMethods', async () => { - const mapMethods = ['addControls', 'addMarkers', 'addMarkersLabel','addPolyline', 'addPolygons', 'addCircles','includePoint'] + const mapMethods = ['addControls', 'addMarkers', 'addMarkersLabel','removeMarker','addPolyline','removePolyline', 'addPolygons','removePolygon', 'addCircles','removeCircle','includePoint'] for (var i = 0; i < mapMethods.length; i++) { await page.callMethod(mapMethods[i]) await page.waitFor(500); diff --git a/pages/component/map/map.uvue b/pages/component/map/map.uvue index b8bb27ab..1740e747 100644 --- a/pages/component/map/map.uvue +++ b/pages/component/map/map.uvue @@ -16,12 +16,17 @@ @confirm="confirm_scale_input"> + - + - - - + + + + + + + 方法示例 @@ -188,7 +193,82 @@ padding: 5, display: 'ALWAYS' } - } + }, + { + id: 2, + latitude: 39.894793, + longitude: 116.321592, + title: '北京西站', + zIndex: '1', + iconPath: '../../../static/location.png', + width: 40, + height: 40, + anchor: { + x: 0.5, + y: 1 + }, + callout: { + content: '北京西站', + color: '#ffffff', + fontSize: 12, + borderRadius: 10, + borderWidth: 2, + borderColor: '#333300', + bgColor: '#ff5500', + padding: 5, + display: 'ALWAYS' + } + }, + { + id: 3, + latitude: 39.902344, + longitude: 116.484822, + title: '北京东站', + zIndex: '1', + iconPath: '../../../static/location.png', + width: 20, + height: 20, + anchor: { + x: 0.5, + y: 1 + }, + callout: { + content: '北京东站', + color: '#ffffff', + fontSize: 12, + borderRadius: 10, + borderWidth: 2, + borderColor: '#333300', + bgColor: '#ff5500', + padding: 5, + display: 'ALWAYS' + } + }, + { + id: 4, + latitude: 39.865011, + longitude: 116.379007, + title: '北京南站', + zIndex: '1', + iconPath: '../../../static/location.png', + width: 40, + height: 40, + anchor: { + x: 0.5, + y: 1 + }, + callout: { + content: '北京南站', + color: '#ffffff', + fontSize: 12, + borderRadius: 10, + borderWidth: 2, + borderColor: '#333300', + bgColor: '#00aa00', + padding: 5, + display: 'ALWAYS' + } + }, ]; @@ -390,9 +470,23 @@ const markers = reactive([] as Markers[]); const addMarkers = () => { + scale.value = 11 markers.push(...testMarkers); }; + const removeMarker = () => { + const index = markers.findIndex(marker => marker.id === 4); + if (index !== -1) { + delete markers[index].label; + markers.splice(index, 1); + }else{ + uni.showToast({ + title: '未找到该标记点', + icon: 'none' + }); + } + }; + const addMarkersLabel = () => { markers.forEach((marker, index) => { marker.label = { @@ -413,9 +507,14 @@ const polyline = ref([] as Polyline[]); const addPolyline = () => { - scale.value = 12; + scale.value = 11; polyline.value = testPolyline; }; + const removePolyline = () => { + if (polyline.value.length > 1) { + polyline.value.splice(0, 1); + } + }; const polygons = ref([] as Polygons[]); @@ -423,6 +522,11 @@ scale.value = 10; polygons.value = testPolygons; }; + const removePolygon = () => { + if (polygons.value.length > 1) { + polygons.value.splice(0, 1); + } + }; const circles = ref([] as Circles[]); @@ -430,6 +534,12 @@ scale.value = 10; circles.value = testCircles; }; + const removeCircle = () => { + if (circles.value.length > 1) { + circles.value.splice(0, 1); + } + }; + const showCompass = ref(true); const enable3D = ref(true); @@ -528,6 +638,22 @@ console.log(error) } }); + map.value.translateMarker({ + markerId: 2, + destination: { + latitude: 39.902344, + longitude: 116.484822, + }, + autoRotate: true, + rotate: 0, + duration: 2000, + success: ret => { + console.log('handleTranslateMarker',JSON.stringify(ret)); + }, + fail: error => { + console.log(error) + } + }); } }; @@ -623,9 +749,13 @@ addControls, addMarkers, addMarkersLabel, + removeMarker, addPolyline, + removePolyline, addPolygons, + removePolygon, addCircles, + removeCircle, includePoint, handleGetCenterLocation, handleGetRegion, -- GitLab