     @map.addControl(nav)
 
   runRemoteCommand: (data) =>
-    return if !@remote.is_enabled() || @remote.myMessage(data)
-
-    if @remote[data.command]?
-      @remote[data.command](@, data, true)
-    else
-      console.log "Unknown command: #{data.command}"
+    @remote.runCommand(@, data)
 
   featurePopup: (e) =>
     features = @map.queryRenderedFeatures(e.point, { layers: @clickable_layers });

# You can use CoffeeScript in this file: http://coffeescript.org/

class RemoteWorkspace
  constructor: (@channel_key) ->
    @enable()

  hideLayer: (ws, data) ->
    return if @myMessage(data)
    ws.hideLayer(data.name, true)

  showLayer: (ws, data) ->
    return if @myMessage(data)
    ws.showLayer(data.name, true)

  move: (ws, data) ->
    return if @myMessage(data)
    # ws.moveTo(data, true)
    location.hash = data.hash

  setStyle: (ws, data) ->
    return if @myMessage(data)
    ws.setStyle(data.name, true)

  myMessage: (data) =>
    return data.sentBy == @channel_key

    data.sentBy ||= @channel_key

    # only broadcast message if we generated the event
    App.workspaces.send(data) if @commandEnabled(data.command) && @myMessage(data)

  commandEnabled: (command) =>
    cmdType = (type for type, cmdlist of @commandTypes when command in cmdlist)
    @is_enabled(cmdType)

  is_enabled: (type) =>
    @syncState[type]

  setSyncState: (type, state) =>
    if type == 'all'
      for name,value in @syncState
        @syncState[name] = state
    else
      @syncState[type] = state

  enable: (type = 'all') =>
    @setSyncState(type, true)

  disable: (type = 'all') =>
    @setSyncState(type, false)

class Workspace
  constructor: (el, channel_key) ->
