Well, surely you can tell when you've switched from showing one background to the other.
In what context? If you do it within the shadowcasting function, you now have another bit of state to track, and it's already a lot to handle. If you do it in the render pass, it has to somehow find the edges. In the code as it is each tile is rendered totally independently, the thing that is merged is various overlapping arrays of data like transparency, the various cell contents, lighting, etc.
What would happen if you had a portal, which another end is next to another portal? Would you be able to view the third location through two portals?
Not implemented currently, but you could write a reference to the map location the portal goes to to the portal array instead of a simple boolean, and recurse through portals. It wouldn't be much harder. The place where it becomes a pain is keeping track of all these different map locations.
Which reminds me, I forgot to outline how that works.
DDA stores map data in chunks we call "submaps", each submap has all the data associated with a 12x12 chunk of map. There is a data structure that is essentially a 11x11 grid of these submaps that stays centered on the player at all times. For the portal destination, we load a second map at the new location, and pull data from it when rendering the portal destination. We'd need to load one of these for each portal in range, recursively. This implies having all the monsters, fields, etc for each portal destination loaded (submaps are synced back to disk and deleted when the player leaves the area, and loaded on-demand when they enter an area). also there is a certain amount of per-turn caching that has to happen, regenerting the transparency maps for each map and running dynamic lighting. Luckily we only have to run FOV once for the visible area, the fact that we're using portals doesn't change that, each visible square is still only visited once, for a worst case of 121x121 squares visited.
This was also quite a pain to deal with when teleporting through a portal, I had to juggle the main map and the portal destination map around and get all their state set up right.
What about if the other end of the second portal would be behind of you, would you see yourself, staring into infinity?
This is a little tricky, it implies that multiple maps have the same submaps loaded, so there might be conflicts between them. It's something I need to address for other reasons at some point, for now I'm deferring that and only loading portals at locations distant from the player.