fix: 在用户拒绝定位权限时避免调用地图includePoints
当用户拒绝定位权限时,isLocationAuthDenied状态为true,此时调用mapCtx.includePoints会失败。在调用includePoints前添加权限检查,防止在权限被拒绝时执行地图操作。同时扩展权限检查逻辑,将undefined状态也视为权限拒绝。
| | |
| | | } else { |
| | | const mapCtx = Taro.createMapContext('map'); |
| | | const points = extractPointsFromPolygons(newPolygons); |
| | | mapCtx.includePoints({ |
| | | points: points, |
| | | padding: [100, 100, 100, 100] |
| | | }); |
| | | if (!isLocationAuthDenied) { |
| | | mapCtx.includePoints({ |
| | | points: points, |
| | | padding: [100, 100, 100, 100] |
| | | }); |
| | | } |
| | | } |
| | | } |
| | | } else { |
| | |
| | | Taro.getSetting({ |
| | | success: (res) => { |
| | | const auth = res.authSetting['scope.userLocation']; |
| | | if (auth === false) { |
| | | if (auth === false || auth === undefined) { |
| | | setIsLocationAuthDenied(true); |
| | | setMapScale(3); |
| | | setLatitude(DEFAULT_LATITUDE); |
| | |
| | | const points = extractPointsFromPolygons(nextPolygons); |
| | | if (points.length > 0) { |
| | | const mapCtx = Taro.createMapContext('map'); |
| | | mapCtx.includePoints({ |
| | | points: points, |
| | | padding: [100, 100, 100, 100] |
| | | }); |
| | | if (!isLocationAuthDenied) { |
| | | mapCtx.includePoints({ |
| | | points: points, |
| | | padding: [100, 100, 100, 100] |
| | | }); |
| | | } |
| | | setTimeout(() => { |
| | | mapCtx.getCenterLocation({ |
| | | success: (res) => { |