Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the method for javascript to delete the specified cover

Shulou Source: shulou.com Published: 2022-06-02 15:58:58 10月02日 Update

This article mainly explains the "javascript delete designated coverage method is what", the article explained the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in-depth, together to study and learn "javascript delete designated coverage method is what" it!

Baidu Maps provides a way to remove all coverings, as well as a way to delete specified coverings. Delete all the coverings needless to say, delete at any time, the code is just one sentence: map.clearOverlays ()

However, it is not easy for many newcomers to delete the specified overlay.

Reason: declared variables, not stored independently, do not know how to find the variable, and then pass the variable as a parameter to perform deletion.

This article first provides a way to delete a specified type of overlay:

/ / openGPS.cn prompt: delete all broken line coverings function clearAllPolyline () {var allOverlay = map.getOverlays (); for (var I = 0; I < allOverlay.length; iTunes +) {if (allOverlay [I] .toString () = "[object Polyline]") {map.removeOverlay (allOverlay [I]) } / / openGPS.cn prompt: delete all lable coverings function clearAllLable () {var allOverlay = map.getOverlays (); for (var I = 0; I < allOverlay.length) Map.removeOverlay +) {if (allOverlay [I] .toString () = = "[object Marker]") {map.removeOverlay (allOverlay.toString ()); / / pay attention to how to get lable}

Then, before talking about how to delete a particular cover, there is a premise: before creating a cover that needs to be manipulated, you need to assign an id to it. In my example, all the Marker attributes are assigned an id to the Marker object using marker.imei = "xxxxxx"; (tip: remember the syntax features of js, direct attribute assignment can be used), traversal with the check of the id to delete the overlay.

/ * openGPS.cn hint: in my example, all Marker attributes are marker.imei = "xxxxxx" Assigns an id to the Marker object, so my way of writing is: get all the coverings first: then determine whether the overlay is of Marker type; then determine whether it is the id (imei) I want to delete; then get the target object and perform the delete operation * / function getMapMarker (imei) {var reMarker = null Var allOverlay = map.getOverlays (); for (var I = 0; I < allOverlay.length; iTunes +) {if (overlay [I] .toString () = "[object Marker]") {if (overlay [I] .getTitle () = imei) {reMarker = allOverlay [I]; break } return reMarker;} Thank you for your reading, the above is the content of "what is the method for javascript to delete specified coverings". After the study of this article, I believe you have a deeper understanding of what the method of deleting designated coverings by javascript is, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Overlays methods variables objects properties methods learning hints content examples types no code writing premises reasons parameters maps that is ideas Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi NVidia Huawei Shulou Information MariaDB