Since i’m currently building an application which is both reliant to the TomTomAPI, and React, i’m not sure if i’m in the right place to get this question out, but ill try my luck i guess?
I’ve got an application, where if i select a certain space on my tomtom map, it shows some details about this selection. However i’ve got 3 issues. The first one is that once I try to select more than 1 item, it will only show the first selection, until after i’ve updated one of my selections. The first is that once I try to update my selection, the details don’t seem to update. The second issue is that once I delete a selection of mine, and I select a different part of the map, it somehow shows details of the selections I had previously deleted. I’m going to put some screenshots in for you to visualise my problem.
Application as normal
2 Selections, only 1 with details
2 selections after updating 1, however these details are incorrect
Deleted all selections, but somehow, still one of the selection details is there
Placed 1 selection, but somehow i now have 3 sets of details
My code
let [TestList, setTestList] = useState([])
function deleteFeatures(features, map) {
features.forEach(function(feature) {
shapes = shapes.filter(function(shape) {
if (feature.id === shape.id) {
var object = null;
shapeList.forEach(element => {
if(element.id === shape.id){
object = element;
innerstring = innerstring.replace(element.HTMLText, "")
}
});
// document.getElementById('listOfSelected').innerHTML = innerstring;
shapeList[object.teller].HTMLText = ""
let punten = shapeList[object.teller].punten
punten.forEach(punt => {
filterAddMarker(punt, map)
});
shape.popup.remove();
document.getElementById("markersOver").innerHTML = "<h1>Nog "+ markers.length +" locaties over</h1>"
var tussenlijst = [];
TestList.forEach(element2 => {
if(element2.id === shape.id){
console.log(element2);
tussenlijst.push(element2)
}
});
var tussenlijst2 = []
console.log("Tussenlijst")
console.log(tussenlijst)
console.log("")
tussenlijst.forEach(x => {
tussenlijst2 = TestList.filter(y => y.id !== x.id)
})
console.log("Tussenlijst2")
console.log(tussenlijst2)
console.log("")
console.log("Testlist")
console.log(TestList)
setTestList(tussenlijst2)
console.log(TestList)
return false;
} else {
return true;
}
});
});
innerstring.replace()
// updateAndShowTotalArea();
}
function Shape(id, coordinates, map) {
let punten = pointCheck(coordinates)
let puntenlengte = punten.length
this.id = id;
this.area = calcAreaFromCoordinates(coordinates);
this.popup = new tt.Popup({
closeButton: false,
closeOnClick: false,
className: 'tt-popup -black',
anchor: 'top'
})
.setLngLat(calculatePopupPosition(coordinates))
.setHTML(id)
.addTo(map);
let HTMLText = getAutoHTML(this.id, punten, areaToString(this.area))
// let tussenlijst = TestList;
TestList.push({id: this.id, Punten: punten, PuntenLengte: puntenlengte, AreaString: areaToString(this.area)})
setTestList(TestList)
setCounter(counter + 1)
switchTheKey()
punten.forEach(punt => {
filterRemoveMarker(punt)
});
shapeList.push({id, HTMLText, teller, punten})
innerstring += HTMLText
// document.getElementById('listOfSelected').innerHTML = innerstring;
document.getElementById("markersOver").innerHTML = "<h1>Nog "+ markers.length +" locaties over</h1>"
teller++;
this.update = function(coordinates) {
let punten = pointCheck(coordinates)
this.area = calcAreaFromCoordinates(coordinates);
this.popup.setLngLat(calculatePopupPosition(coordinates));
this.popup.setHTML(id);
let HTMLText = getAutoHTML(this.id, punten, areaToString(this.area))
console.log(this.id)
let tussenlijst = []
console.log("Kaas")
tussenlijst = TestList.filter(x => x.id !== this.id )
// TestList.forEach(element => {
// if(element.id !== this.id){
// tussenlijst.push(element)
// }
// });
console.log(tussenlijst.length)
tussenlijst.push({id: this.id, Punten: punten, PuntenLengte: puntenlengte, AreaString: areaToString(this.area)})
console.log("//Kaas")
console.log(tussenlijst)
console.log("///Kaas")
setTestList(tussenlijst)
// TestList.push({id: this.id, Punten: punten, PuntenLengte: puntenlengte, AreaString: areaToString(this.area)})
var object = null;
shapeList.forEach(element => {
if(element.id === this.id){
object = element;
innerstring = innerstring.replace(element.HTMLText, HTMLText)
}
});
// document.getElementById('listOfSelected').innerHTML = innerstring;
shapeList[object.teller].HTMLText = HTMLText
shapeList[object.teller].punten.forEach(punt => {
filterAddMarker(punt, map)
});
punten.forEach(punt => {
filterRemoveMarker(punt)
});
shapeList[object.teller].punten = punten
document.getElementById("markersOver").innerHTML = "<h1>Nog "+ markers.length +" locaties over</h1>"
};
}
Is there somebody here able to help me out?