mapsense / mapsense.js

Mapsense.js
Other
88 stars 22 forks source link

interact() by default #11

Closed sttawm closed 9 years ago

sttawm commented 9 years ago

If interaction is added to the map by default, we need a way to disable it. One approach involves storing a reference to the interact object and providing a getter/setter

ms.map = function() {
    var map = {},
        ...
        interact = ms.interact();

    add(interact);

    map.interact = function(x) { 
        if (!arguments.length) return interact;
        interact.add(x? map : null);
    }

    ...
};

// disable interact
map.interact(false);

Could also just have a plain getter and do:

ms.map = function() {
    var map = {},
        ...
        interact = ms.interact();

    add(interact);

    map.interact = function() {  return interact; }
    ...
};

// disable interact
map.remove(map.interact());

These don't seem so bad, and are simple enough. map.add(ms.interact()) is probably common enough that automating it is worth it.

Thoughts?

.

mpruett commented 9 years ago

Done.