yandex / yandex/yandex_maps_mapkit
Предположительно неправильно работает screenToWorld
Nobody has claimed this yet.
- Dominant language
- Dart
- Stars
- 11
- Forks
- 6
- PR merge metrics
- No merged PRs in 30d
Description
Пытаюсь реализовать рисование области пальцем. Либо некорректно работает преобазование в методе screenToWorld, либо я что-то делаю не так.
zoom установленный по умолчанию.
import 'package:flutter/material.dart';
import 'package:yandex_maps_mapkit/mapkit.dart';
import 'package:yandex_maps_mapkit/yandex_map.dart';
class MainPage extends StatefulWidget {
const MainPage({Key? key}) : super(key: key);
@override
State<MainPage> createState() => _MainPageState();
}
class _MainPageState extends State<MainPage> {
MapWindow? _mapWindow;
final List<Point> _polygonPoints = [];
bool _isDrawing = false;
@override
Widget build(BuildContext context) {
return Scaffold(
body: GestureDetector(
onLongPressStart: _handleLongPressStart,
onLongPressMoveUpdate: _handleLongPressMoveUpdate,
onLongPressEnd: _handleLongPressEnd,
child: YandexMap(
onMapCreated: _onMapCreated,
),
),
);
}
void _onMapCreated(MapWindow mapWindow) {
_mapWindow = mapWindow;
}
void _handleLongPressStart(LongPressStartDetails details) {
final RenderBox renderBox = context.findRenderObject() as RenderBox;
print(renderBox.localToGlobal(details.globalPosition));
final Point? point = _screenPointToMapPoint(renderBox.globalToLocal(details.globalPosition));
setState(() {
_polygonPoints.clear();
_polygonPoints.add(point!);
_isDrawing = true;
});
}
void _handleLongPressMoveUpdate(LongPressMoveUpdateDetails details) {
final RenderBox renderBox = context.findRenderObject() as RenderBox;
final Point? point = _screenPointToMapPoint(renderBox.globalToLocal(details.localPosition));
if (_isDrawing) {
setState(() {
_polygonPoints.add(point!);
});
}
}
Point? _screenPointToMapPoint(Offset localPosition) {
final point = ScreenPoint(x: localPosition.dx, y: localPosition.dy);
print(point);
print(_mapWindow!.screenToWorld(point));
return _mapWindow!.screenToWorld(point);
}
void _handleLongPressEnd(LongPressEndDetails details) {
if (_isDrawing) {
setState(() {
_isDrawing = false;
if (_polygonPoints.length > 3) {
_drawPolygon();
}
});
}
}
void _drawPolygon() {
if (_mapWindow != null && _polygonPoints.isNotEmpty) {
final polygon = Polygon(
LinearRing(_polygonPoints), []
);
_mapWindow!.map.mapObjects.addPolygon(polygon);
}
}
}
I/flutter ( 7543): Offset(152.0, 362.1)
I/flutter ( 7543): ScreenPoint(x: 151.9950284090909, y: 362.14950284090907)
I/flutter ( 7543): Point(latitude: 78.99708352591344, longitude: 40.39708695628468)
в итоге область появляется ближе к верхнему левому углу при рисовании ближе к центру.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with _handleLongPressStart, _handleLongPressMoveUpdate, and _screenPointToMapPoint, then inspect how the GestureDetector positions relate to MapWindow.screenToWorld input. Reproduce the reported offset and compare the coordinates used for the start and move events. Done means the drawn polygon follows the user's finger instead of appearing toward the upper-left.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart, flutter
- Domain
- mobile
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100