- bug:循环创建三个圆形区域 ,数组设置为[{raduis:500,color:“#FF0000”}],然后循环取颜色会莫名其妙报错
- 修改为 strokeColor: [“#FF0000”, “#1EE3C2”, “#3772E9”][i]即可
initAMap() {AMapLoader.load({key: "130cca3be68a2ff0fd5ebb6de25e4eac", }).then((AMap) => {this.map = new AMap.Map("containerMap", {rotateEnable: true,pitchEnable: true,zoom: 13,pitch: 50,rotation: -15,viewMode: "3D", zooms: [2, 20],center: [119.419251, 32.400703],mapStyle: "amap://styles/blue", });this.map.on("complete", () => {console.log("地图加载完成");if (this.position) {var marker = new AMap.Marker({position: new AMap.LngLat(...this.position),icon: new AMap.Icon({image: fireIcon,imageSize: new AMap.Size(26, 34),}),});this.map.add(marker);var center = new AMap.LngLat(...this.position);var radius = [500, 1000, 1500];radius.map((item, i) => {var circle = new AMap.Circle({center: center, radius: item, borderWeight: 3, strokeColor: ["#FF0000", "#1EE3C2", "#3772E9"][i], strokeOpacity: 1, strokeWeight: 2, fillOpacity: 0.1, fillColor: ["#FF0000", "#1EE3C2", "#3772E9"][i], zIndex: 50, });this.map.add(circle);this.map.setFitView([circle]);function getEdgePointOfCircle(center, radius, bearing) {var lat = center[1];var lon = center[0];var brngRad = (bearing * Math.PI) / 180;var R = 6371000;var lat2 = Math.asin(Math.sin((lat * Math.PI) / 180) * Math.cos(radius / R) Math.cos((lat * Math.PI) / 180) *Math.sin(radius / R) *Math.cos(brngRad));var lon2 =(lon * Math.PI) / 180 +Math.atan2(Math.sin(brngRad) *Math.sin(radius / R) *Math.cos((lat * Math.PI) / 180),Math.cos(radius / R) -Math.sin((lat * Math.PI) / 180) * Math.sin(lat2));return [(lon2 * 180) / Math.PI, (lat2 * 180) / Math.PI];}let addRadiusLabel = () => {var labelPosition = getEdgePointOfCircle(this.position,item,90);var text = new AMap.Text({text: item + "米", anchor: "center", draggable: false, cursor: "pointer", angle: 0, style: {padding: ".1rem 0.2rem","border-radius": ".1rem","background-color": "transparent",border: "1px solid rgba(0, 0, 0, 0.5)","border-color": ["#FF0000", "#1EE3C2", "#3772E9"][i],"text-align": "center","font-size": ".1875rem",color: "white",},position: labelPosition, });text.setMap(this.map); };addRadiusLabel();});}});}).catch((e) => {console.log(e);});},