


How to clear the specified overlay using Baidu Maps API? How to do it specifically?
Below I will share with you a method of clearing the specified overlay based on Baidu Maps API. It has a good reference value and I hope it will be helpful to everyone.
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. Therefore, I encountered the problem of clearing the specified overlay, and could not find it after various searches. The perfect solution. Through my own thinking, 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; } } }
is done by traversing all overlays Filter the overlays to be removed;
For a type of overlays to be removed; you can set restrictions when adding overlays;
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()
none prohibits the overlay from being cleared in the map.clearOverlays method. (Added since 1.1)
I don’t need to remove the marker here, so the settings are as follows:
marker.disableMassClear();
Step 2: Clear the overlay to be cleared , here you need to clear all the Polyline without clearing the marker. Now you can directly use
map.clearOverlays();
. This way you can easily clear all the Polyline and keep the marker;
Step 3: When you need to remove the marker later, you can use the enableMassClear() method to cancel the prohibition of clearing;
enableMassClear()
none allows the overlay to be in the map. Cleared in the clearOverlays method. (Added since 1.1)
But each marker needs to be restored, so it needs to be traversed:
var allOverlay = map.getOverlays(); for (var i = 0; i < allOverlay.length; i++) { allOverlay[i].enableMassClear(); }
This restores the clearable operations of all overlays.
A simple three-step setup can efficiently operate the specified type of covering.
The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.
Related articles:
How to implement ajax front-end and back-end cross-domain requests
Customize ajax to support cross-domain components (detailed tutorial)
How to implement verification code to obtain countdown effect through WeChat applet
The above is the detailed content of How to clear the specified overlay using Baidu Maps API? How to do it specifically?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Baidu Map APP has now become the preferred travel navigation software for many users, so some of the functions here are comprehensive and can be selected and operated for free to solve some of the problems that you may encounter in daily travel. You can all check some of your own travel routes and plan some of your own travel plans. After checking the corresponding routes, you can choose appropriate travel methods according to your own needs. So whether you choose some public transportation, Cycling, walking or taking a taxi can all satisfy your needs. There are corresponding navigation routes that can successfully lead you to a certain place. Then everyone will feel more convenient if they choose to take a taxi. There are many drivers They are all able to take orders online, and taxi-hailing has become super

In daily travel, we often need to take a taxi, and now Baidu Maps also provides a taxi service, which is convenient and fast. However, many people still don’t know how to pay after taking a taxi on Baidu Maps. Below, we will introduce in detail how to pay for taxis on Baidu Maps. How to pay for a taxi on Baidu Map 1. First open the Baidu Map APP and enter the main page; 2. Then jump to the page shown in the picture below and click [Taxi] on the right; 3. Then enter the taxi function page in the picture below , select [Personal Center]; 4. Then on the Personal Center page, find [Payment Management]; 5. Finally, on the payment management function page, select the payment method you want to activate and click [Go to Activate].

If you want to add a new location on Baidu Maps, you may need to go through some complicated steps. But don’t worry, next I will explain in detail how to add a new place on Baidu Maps, making it easier for you to share your location information or help others find their destination. How to add a new location on Baidu Map 1. First open the Baidu Map APP and enter the main page; 2. Then enter the main page as shown below and click the [Report] button on the right; 3. Then jump to the reporting function page , select the [Add Location] service below; 4. Then enter the information in the [Other Information] box in the Add Location area; 5. Finally enter the corresponding information and click [Submit] at the bottom to complete.

Baidu Maps has a 3D real-life map function, so how to view the 3D real-life map? Users need to find more options in My, and then find the 3D map in it to view the map. This introduction to the method of viewing 3D real-life maps can tell you how to set it up. The following is a detailed introduction, so take a look. Baidu Map usage tutorial How to view the 3D real-life map of Baidu Map Answer: Go to My-More-3D Map Specific method: Mobile version: 1. First, click My on the lower right. 2. Find more functions inside. 3. Click on the 3D real scene to use it. Web version: 1. First, you need to enter https://map.baidu.com to enter the web version. 2. Click View method in the lower right corner.

Baidu Map Navigation mobile version free download is a very professional mobile map navigation software. The navigation function in the software is very powerful. As long as you want to go, you can find the most accurate travel plan. It is very convenient to go wherever you want to go. At the same time, you can also use other navigation functions. You can download and use the voice packs of various celebrities for free. Various navigation modes can be used online to protect everyone's travel safety. You can also scan the code to take a bus more conveniently. It is a must-have travel navigation assistant. , don’t worry about getting lost, now the editor will carefully introduce to Baidu Map partners how to view 3D real-time street view online. 1. Open Baidu Maps and click More in the common function bar. 2. Then search to find the 3D real scene. 3. Then enter the 3D viewing interface. 4. Such as

There are many functions above, especially for maps that can mark multiple places. When we know some places, we will definitely use some punctuation functions, so that we can bring you a variety of different aspects. Some of the functions you mark will produce distance differences, that is, you can know how far away they are. Of course, some names and detailed information of the above places will also be displayed. However, many netizens may not be familiar with some of the above. The content information is not very clear, so in order to allow everyone to make better choices in various aspects, today the editor will bring you some choices in various aspects, so friends who are interested in ideas, If you are also interested, come and give it a try. Standard

With the popularity of online taxi hailing, more and more people choose to use Baidu Maps to hail taxis. However, for users who need to reimburse or issue invoices, how to issue an invoice after taking a taxi on Baidu Map is a more important issue. This article will introduce you how to issue an invoice after taking a taxi on Baidu Maps. How to invoice Baidu Map Taxi 1. First open the Baidu Map APP and enter the [Avatar] in the upper left corner of the main page; 2. Then enter the personal center function page and select the [Taxi] function as shown below; 3. Then Go to the taxi function page and click the [Personal Center] button on the right; 4. Then in the personal center area, select [Invoicing]; 5. Then on the invoicing page, click [Travel Service Invoicing]; 6. Press the order On the invoicing function page, check the

This website reported on July 24 that recently, Moore Thread and Baidu Maps signed a strategic cooperation agreement. Both parties will leverage their respective advantages in technology and products to jointly promote technological innovation in digital twin maps. According to the cooperation agreement, the two parties will focus on the construction of the digital twin map project, taking advantage of Baidu Map's map engine advantages, digital twin technology advantages, map big data application advantages, and the 3D graphics rendering and AI computing technology advantages of Moore's thread full-featured GPU to actively carry out In-depth and extensive continuous cooperation will jointly promote the application and large-scale implementation of digital twin map solutions. According to the official introduction of Moore Thread, map data is a key asset of the country, and digital twin maps especially highlight its importance in high-load rendering scenarios, which has a significant impact on the rendering performance and performance of GPUs.
