Skip to content

Commit

Permalink
Removing dynamic layers (#44)
Browse files Browse the repository at this point in the history
* Removing dynamic layers

* version bump
  • Loading branch information
aviklai committed Dec 29, 2022
1 parent e33016c commit acfa898
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 39 deletions.
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "react-leaflet-google-layer",
"version": "2.1.0",
"version": "2.2.0",
"description": "React leaflet wrapper of leaflet.gridlayer.googlemutant",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
39 changes: 1 addition & 38 deletions src/index.ts
Expand Up @@ -36,41 +36,4 @@ const createLeafletElement = (props: IProps, context: LeafletContextInterface) =
return { instance, context };
}

const updateLeafletElement = (
instance: L.GridLayer,
props: IProps,
prevProps: IProps
) => {
const prevGoogleMapsAddLayers = prevProps.googleMapsAddLayers
? prevProps.googleMapsAddLayers.map((addLayer: IGoogleMapsAddLayer) => addLayer.name)
: [];
const currentGoogleMapsAddLayers = props.googleMapsAddLayers
? props.googleMapsAddLayers.map((addLayer: IGoogleMapsAddLayer) => addLayer.name)
: [];

if (props.googleMapsAddLayers) {
props.googleMapsAddLayers.forEach((layer) => {
if (prevGoogleMapsAddLayers.indexOf(layer.name) === -1) {
(instance as L.gridLayer.GoogleMutant).addGoogleLayer(
layer.name,
layer.options
);
}
});
}

if (prevProps.googleMapsAddLayers) {
prevProps.googleMapsAddLayers.forEach((layer) => {
if (currentGoogleMapsAddLayers.indexOf(layer.name) === -1) {
(instance as L.gridLayer.GoogleMutant).removeGoogleLayer(layer.name);
}
});
}

updateGridLayer(instance, props, prevProps);
};

export default createLayerComponent<L.GridLayer, LayerProps & IProps>(
createLeafletElement,
updateLeafletElement
);
export default createLayerComponent<L.GridLayer, LayerProps & IProps>(createLeafletElement, updateGridLayer);

0 comments on commit acfa898

Please sign in to comment.