Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove added layer from map #275

Open
amirsamani opened this issue Oct 3, 2022 · 2 comments
Open

remove added layer from map #275

amirsamani opened this issue Oct 3, 2022 · 2 comments

Comments

@amirsamani
Copy link

amirsamani commented Oct 3, 2022

hi
I have added a layer to the map with below code and after I want to remove that layer from the map, how can I do this?

        vectorUrl ='http://localhost:7800/asphalt/{z}/{x}/{y}.pbf';

        vectorTileStyling[vectorLayerId] = {
            fill: true,
            fillColor: 'green',
            fillOpacity: 0.1,
            color: 'green',
            opacity: 0.7,
            weight: 2,
            // dashArray: '2, 6',
        }

        var vectorTileOptions = {
            rendererFactory: L.canvas.tile,
            subdomains: '0123',	// 01234 for openmaptiles, abcd for mapbox
            vectorTileLayerStyles: vectorTileStyling
        }

            bandar_asphalt = L.vectorGrid.protobuf(vectorUrl, vectorTileOptions).addTo(MAP);`
@amirsamani
Copy link
Author

Does anyone know how this is done?

@dpakprajul
Copy link

This code snippet could help you to remove the added layer from the map. If you click on the map, the just-added layer will be removed. Or you can introduce a button in HTML and write a Jquery.

HTML:

VT Layer

JS:
//remove and add layer on clicking checkbox vt_layer using jquery
$("#vt_layer").click(function () {
if (this.checked) {
map.addLayer(bandar_asphalt);
} else {
map.removeLayer(bandar_asphalt);
}
}
);

Without using JQuery:
MAP.on("click", function (e) {
if (map.hasLayer(bandar_asphalt)) {
map.removeLayer(bandar_asphalt);
}
});

Before

image

After

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants