do you want to put `window.map.hasLayer(window.plugin.portalOwner.layer)` to the top of the if?