This time I will bring you Baidu Map to display markers and Polyline, and Baidu Map to display markers and Polyline Precautions What are the practical cases below, let’s take a look one time.
Recently I was working on a project using the Baidu Map API. I needed to display markers and polylines on the map at the same time, and the polylines needed to be displayed or cleared based on clicks, so I encountered the problem of clearing the designated covering. I couldn't find a perfect solution after searching . After thinking on my own, I found a way to solve this problem and posted it to share with everyone. Okay, let’s get to the point:
There are two methods for clearing overlays: map.removeOverlay() or map.clearOverlays(). The clearOverlays() method moves one at a time. In addition to all overlays, removeOverlay() removes one specified overlay at a time. Obviously, I want to remove one type of Polyline overlay at a time, and neither method is applicable.
Baidu demo (http://developer.baidu.com/map/jsdemo.htm#c1_17) has an example of removeOverlay(), as follows:function deletePoint(){ var allOverlay = map.getOverlays(); for (var i = 0; i < allOverlay.length -1; i++){ if(allOverlay[i].getLabel().content == "我是id=1"){ map.removeOverlay(allOverlay[i]); return false; } } }
Step 1: When adding an overlay, set disableMassClear() for the overlay that does not need to be removed; the official website document explains it as follows
disableMassClear()
marker.disableMassClear();
Second step: Clear the covering to be cleared. Here you need to clear all the Polyline without clearing the marker. Now you can directly use
map.clearOverlays();
Step 3: When you need to remove the marker later, you can use the enableMassClear() method to cancel the prohibition of clearing;
enableMassClear()
var allOverlay = map.getOverlays(); for (var i = 0; i < allOverlay.length; i++) { allOverlay[i].enableMassClear(); }
vue.js implements a single pop-up box
Detailed explanation of the use of javascript trie prefix tree
The above is the detailed content of Display markers and Polyline in Baidu map. For more information, please follow other related articles on the PHP Chinese website!