Closed Anfet closed 1 month ago
Further investigation revealed that there is a double call to updateMapObjects
with toAdd
argument from flutter.
Afterwards the android plugin executes commands without any verification, thus creating duplicate controllers and/or placemarks.
Easiest hotfix would be to add checks to any add
methods and verify that required controller does not exist.
java/com/unact/yandexmapkit/MapObjectCollectionController.java
private void addMapObjectCollection(Map<String, Object> params) {
String id = (String) params.get("id");
MapObjectCollectionController mapObjectCollectionController = mapObjectCollections.get(id);
if (mapObjectCollectionController == null) {
mapObjectCollectionController = new MapObjectCollectionController(
mapObjectCollection,
params,
controller
);
mapObjectCollections.put(mapObjectCollectionController.id, mapObjectCollectionController);
} else {
changeMapObjectCollection(params);
}
}
private void addPlacemark(Map<String, Object> params) {
String id = (String) params.get("id");
PlacemarkMapObjectController placemarkController = placemarks.get(id);
if (placemarkController == null) {
placemarkController = new PlacemarkMapObjectController(
mapObjectCollection,
params,
controller
);
placemarks.put(placemarkController.id, placemarkController);
} else {
changePlacemark(params);
}
}
I'd offer a request, but not sure that this is full and correct bugfix. The duplicate command from flutter should not come.
Thx for solution, but new code: private void addPlacemark(Map<String, Object> params) { String id = (String) params.get("id"); PlacemarkMapObjectController placemarkController = placemarks.get(id);
if (placemarkController == null) {
placemarkController = new PlacemarkMapObjectController(
clusterizedPlacemarkCollection,
params,
controller
);
placemarks.put(placemarkController.id, placemarkController);
} else {
changePlacemark(params);
}
// PlacemarkMapObjectController placemarkController = new PlacemarkMapObjectController(
// clusterizedPlacemarkCollection,
// params,
// controller
// );
// placemarks.put(placemarkController.id, placemarkController);
}
if state changes too quickly than addPlacemark added two or more markers
For ios, you will need to change in two files as well: 1) MapObjectCollectionController 2) ClusterizedPlacemarkCollectionController
In the first file, you need to change the addPlacemark and addMapObjectCollection functions And in the second only addPlacemark
addPlacemark in MapObjectCollectionController
private func addPlacemark(_ params: [String: Any]) {
guard let id = params["id"] as? String else { return }
if placemarks[id] != nil {
changePlacemark(params)
} else {
let newPlacemarkController = PlacemarkMapObjectController(
parent: mapObjectCollection,
params: params,
controller: controller!
)
placemarks[newPlacemarkController.id] = newPlacemarkController
}
}
addMapObjectCollection in MapObjectCollectionController
private func addMapObjectCollection(_ params: [String: Any]) {
guard let id = params["id"] as? String else { return }
if mapObjectCollections[id] != nil {
changeMapObjectCollection(params)
} else {
let newController = MapObjectCollectionController(
parent: mapObjectCollection,
params: params,
controller: controller!
)
mapObjectCollections[newController.id] = newController
}
}
and addPlacemark in ClusterizedPlacemarkCollectionController
private func addPlacemark(_ params: [String: Any]) {
guard let id = params["id"] as? String else { return }
if placemarks[id] != nil {
changePlacemark(params)
} else {
let newPlacemarkController = PlacemarkMapObjectController(
parent: clusterizedPlacemarkCollection,
params: params,
controller: controller!
)
placemarks[newPlacemarkController.id] = newPlacemarkController
}
}
if state changes too quickly than addPlacemark added two or more markers
can you please define "quickly"?
any change these bugs will be fixed?
tap/swipe on element in list add marker on map (if in need than with clusters). if user is swiping fast than we have two markers I d'not know at the moment. Users will say :)
Hello!
@Anfet Please provide a working example. Current example is incomplete and I'm unable to reproduce your issue.
there is a double call to updateMapObjects
If you are using a MapObjectCollection
then it is working correctly since internally it wraps all arguments passed to YandexMap.mapObjects
in a MapObjectCollection
.
Encountered the following strange behavior; After the map initialization I try to add placemarks Here is the code.
Problem: 1st execution of code = 10 marks on screen. 2nd executions of code = 20 marks on screen. 3rd+ executions = 20 marks.
As you can see, map Ids are the same. The code is issuing changes
but the internal workings of the map still adds additional marks. I've checked - code everytime is issuing changes.
Tried with clusterized collections and individual placemarks. Same output.
mapkit version: 3.3.3 android dependency: com.yandex.android:maps.mobile:4.3.2-full