how to remove drawn kml shape from map which is parsed by geoXml3 so that we can parse and draw a newone. I am only seeing method of hideDocument and showDocument on geoXml but it doesn't completely remove.
let filename = "http://localhost:5002/Nevada-2.kml";
let myLocation = { lat: 36.737061, lng: -119.7912549 };
function initialize() {
let lat = 43.502745;
let lng = -116.240845;
myLatLng = new google.maps.LatLng(lat, lng);
let zoom = 12;
let myOptions = {
zoom,
center: myLatLng,
};
// create the map
let map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
let geoXml = new geoXML3.parser({
map: map,
});
geoXml.parse(filename);
google.maps.event.addListenerOnce(geoXml, "parsed", function () {
let exist = false;
for (let i = 0; i < geoXml.docs[0].placemarks.length; i++) {
let placemark = geoXml.docs[0].placemarks[i];
if (placemark.polygon) {
if (
google.maps.geometry?.poly.containsLocation(
new google.maps.LatLng(myLocation),
placemark.polygon
)
) {
exist = true;
break;
}
}
}
if (exist) {
new google.maps.Marker({
map: map,
position: myLocation,
});
console.log("EXIST");
} else {
console.log("Doesn't Exist");
console.log("geoXml: ", geoXml);
}
});
}
remove drawn kml shape from map which is parsed by geoXml3
Not sure why you want to completely remove the
geoXmlobject.If you want to do that remove the
letfrom its declaration then usedelete geoXml;to delete it.If you want to make it so
geoXml.showDocument()doesn't display the loaded polygon (or markers or polylines), callgeoXml.hideDocument()(to hide all the objects associated with that KML), then usegeoXml.docs.splice(0);to remove that document's saved data.change the posted code to this (will remove that data when
existisfalse):working code snippet: